Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Finaddicts on October 09, 2013, 07:56:27 PM

Title: Add REST API
Post by: Finaddicts on October 09, 2013, 07:56:27 PM
Let me start off by saying I'm not a developer so this gets confusing for me. I need to add a REST API for email notifications for activations, PM's and post. Here's my situation, I have been searching a couple of forums to try and understand the process. I was using PHP mail for the notifications but they were delayed by days so I switched to SMTP mail. My host is GoDaddy so I'm limited to 250 relays a day or purchase more relays. GoDaddy does have their SMTP relay using email-hosting.secureserver.net but that is delayed as well. I ended up purchasing Elastic Email SMTP relay but GoDaddy doesn't allow 3rd party SMTP from their servers. Does anyone know how I would go about adding the Elastic Email REST API to the SMF forums. If it isn't too hard I would like to try.


Thanks in advance....
Title: Re: Add REST API
Post by: margarett on October 09, 2013, 08:29:01 PM
SMF 2.x has a built in mail queue (IIRC,  per hour, not per day)

Will it suit your needs?
Title: Re: Add REST API
Post by: Finaddicts on October 09, 2013, 10:23:59 PM
I have the built in queue working but once I hit 250 for the day the email will stay in queue until the next day when we get another 250 allotment.
Title: Re: Add REST API
Post by: margarett on October 10, 2013, 02:14:09 AM
Can I ask you how much did that "Elastic" software costed to you?

My advice to you: change host. I don't see anyone wanting to develop an API for that.
Title: Re: Add REST API
Post by: emanuele on October 10, 2013, 04:35:45 AM
Actually it shouldn't be *that* difficult: it would just be a matter of POST some data to an url instead of format the message and pass it to mail smtp_mail.
Title: Re: Add REST API
Post by: Finaddicts on October 10, 2013, 09:59:12 AM
Elastic is about 8.00 a month for 10k relays, the longer you stay with them it drops to 7.20 a month.  They have the sample coding that could be modified and used, I have no idea where I would go to install it.
Title: Re: Add REST API
Post by: emanuele on October 10, 2013, 03:56:45 PM
DISCLAIMER: untested (since I don't have an account there) and the probability it doesn't work is very, very high. ;)

In Subs-Post.php:
Code (find) Select

// Sending HTML?  Let's plop in some basic stuff, then.
if ($send_html)

Code (replace with) Select
$modSettings['elasticmail_url'] = 'https://api.elasticemail.com/mailer/send';
$modSettings['elasticmail_user'] = '';
$modSettings['elasticmail_key'] = '';

if (!empty($modSettings['elasticmail_user']) && !empty($modSettings['elasticmail_key']))
{
global $sourcedir;

$post_data = array(
'username' => $modSettings['elasticmail_user'],
'api_key' => $modSettings['elasticmail_key'],
'from_name' => $from_name,
'from' => empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'],
'to' => implode(';', $to_array),
'subject' => $subject,
'encodingtype' => 1 // <= 7bit...I *think*
);
if ($send_html)
$post_data['body_html'] = $message;
else
$post_data['body_text'] = $message;
if ($from !== null)
$post_data['reply_to'] = $from;

require_once($sourcedir . '/Subs-Package.php');
$posted_data = '';
foreach ($post_data as $key => $val)
$posted_data .= (empty($posted_data) ? '' : '&') . $key . '=' . urlencode($val);
$el_resp = fetch_web_data($modSettings['elasticmail_url'], $posted_data);
}
// Sending HTML?  Let's plop in some basic stuff, then.
elseif ($send_html)


Put your user and account in the two variables up there like this:
$modSettings['elasticmail_user'] = 'username here';
$modSettings['elasticmail_key'] = 'api key here';

And cross your fingers. :P
I'd try it on a test forum first. ;)
Title: Re: Add REST API
Post by: Finaddicts on October 10, 2013, 07:24:09 PM
Quote from: emanuele on October 10, 2013, 03:56:45 PM
DISCLAIMER: untested (since I don't have an account there) and the probability it doesn't work is very, very high. ;)

In Subs-Post.php:
Code (find) Select

// Sending HTML?  Let's plop in some basic stuff, then.
if ($send_html)

Code (replace with) Select
$modSettings['elasticmail_url'] = 'https://api.elasticemail.com/mailer/send';
$modSettings['elasticmail_user'] = '';
$modSettings['elasticmail_key'] = '';

if (!empty($modSettings['elasticmail_user']) && !empty($modSettings['elasticmail_key']))
{
global $sourcedir;

$post_data = array(
'username' => $modSettings['elasticmail_user'],
'api_key' => $modSettings['elasticmail_key'],
'from_name' => $from_name,
'from' => empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'],
'to' => implode(';', $to_array),
'subject' => $subject,
'encodingtype' => 1 // <= 7bit...I *think*
);
if ($send_html)
$post_data['body_html'] = $message;
else
$post_data['body_text'] = $message;
if ($from !== null)
$post_data['reply_to'] = $from;

require_once($sourcedir . '/Subs-Package.php');
$posted_data = '';
foreach ($post_data as $key => $val)
$posted_data .= (empty($posted_data) ? '' : '&') . $key . '=' . urlencode($val);
$el_resp = fetch_web_data($modSettings['elasticmail_url'], $posted_data);
}
// Sending HTML?  Let's plop in some basic stuff, then.
elseif ($send_html)


Put your user and account in the two variables up there like this:
$modSettings['elasticmail_user'] = 'username here';
$modSettings['elasticmail_key'] = 'api key here';

And cross your fingers. :P
I'd try it on a test forum first. ;)

I'll give it a shot....Thank you very much....
Title: Re: Add REST API
Post by: Finaddicts on October 10, 2013, 07:45:53 PM
Wow, just added this to a test forum and it worked......Big Thanks
Title: Re: Add REST API
Post by: margarett on October 10, 2013, 07:48:20 PM
Quote from: margarett on October 10, 2013, 02:14:09 AM
I don't see anyone wanting to develop an API for that.
/me slaps itself in the face :P

Thanks ema ;)

Marked as solved. Feel free to unmark it if you need ;)
Title: Re: Add REST API
Post by: emanuele on October 11, 2013, 02:35:29 AM
Cool! :D
Now it would be nice to pack it as mod... O:-)
Title: Re: Add REST API
Post by: Finaddicts on October 11, 2013, 12:55:16 PM
Just FYI, You do need to go into your hosts DNS settings and add the SPF, DKIM, and CNAME settings for this to work correctly.
Title: Re: Add REST API
Post by: dougiefresh on August 02, 2017, 09:41:01 PM
Topic was continued here (https://www.simplemachines.org/community/index.php?topic=551178.0)....  along with a mod link...