If you have a small number of customers with whom you regularly email back and forth, then youre going to know pretty quickly if theres a problem with email delivery. In this low volume high and delivery confidence case the Wolfram Language SendMail function is a very good solution, regardless whether email is being sent from your Mathematica desktop, from the Wolfram Development Platform (public cloud), from a private Wolfram Cloud, or from CDF documents that run on a customers desktop.
On the other hand, if your business sends, or aspires to grow to a size where it sends, thousands of transactional and marketing emails per day, an email delivery service may give a much better delivery success rate, see for example the Mailgun documentation Email Best Practices guide, which explains how a delivery service manages domain and IP reputation and authentication, handles bounce feedback and unsubscribes, tracks recipient engagement, etc. Regardless of the choice to use SendMail or an email delivery service, be sure to always send something people want.
If youd like to try out an email delivery service, the Mailgun API is easy to call from your desktop or from the Wolfram Development Platform. It takes only a few minutes to create a free account. The signup success page invites you to send a sandbox server test email and even gives cURL code with your name, sandbox domain, email address, and password already entered:
curl -s --user 'api:YOUR-PRIVATE-API-KEY' \
https://api.mailgun.net/v3/YOUR-SANDBOX-DOMAIN-NAME/messages \
-F from='Mailgun Sandbox <postmaster@YOUR-SANDBOX-DOMAIN-NAME>' \
-F to='YOUR-NAME <YOUR-EMAIL-ADDRESS>'\
-F subject='Hello YOUR-NAME' \
-F text='Congratulations YOUR-NAME, you just sent a Mailgun email!'
Simple extensions of this cURL code will add html and attachments to the test email. Cut and paste the appropriate cURL elements into a the MultipartElements option of a Wolfram Language URLFetch command and deploy on the Wolfram Development Platform:
With[{image=Image[Graphics[{Disk[{0,0}, Sqrt[2]], Red, Disk[]}], ImageSize->64]},
CloudDeploy[Delayed[URLFetch["https://api.mailgun.net/v3/YOUR-SANDBOX-DOMAIN-NAME/messages",
"Method"->"POST",
"MultipartElements" -> {
{"from","text/plain"} -> "Mailgun Sandbox <postmaster@YOUR-SANDBOX-DOMAIN-NAME>",
{"to","text/plain"} -> "YOUR-NAME <YOUR-EMAIL-ADDRESS>",
{"subject","text/plain"} -> "Hello YOUR-NAME",
{"text","text/plain"} -> "Congratulations YOUR-NAME, you just sent a Mailgun email!",
{"html","text/plain"} ->
"<html> HTML version of the body <img alt=\"Bullseye\" src=\"data:image/jpeg;base64, " <>
ExportString[image,{"Base64","JPEG"}] <> "\" /> </html>",
{"attachment\"; filename=\"Bullseye.jpg","image/jpeg"} ->
ExportString[image,"JPEG"]},
"Username"->"api","Password"->"YOUR-PRIVATE-API-KEY"]],
FileNameJoin[{$CloudRootDirectory,"MailgunEmailDelivery"}]]]
URLExecute[%]
The last Multipart element name is "attachment" but URLFetch is tricked into adding the filename "Bullseye.jpg" by hiding it within a longer element name. You can deploy this URLFetch to a free account on the Wolfram Development Platform. And Mailgun is easily configured to send email from your own domain. Its that simple! Youll be up and running in a few minutes.
The above code computes both the HTML inline image and the attachment from a Wolfram Language image:
ExportString[image, {"Base64","JPEG"}]
ExportString[image, "JPEG"]
To instead import the inline image and attachment from a file, substitute Wolfram Language expressions:
ExportString[Import[file, "String"], "Base64"]
Import[file, "String"]
11/17/15 update of original 3/27/15 Wolfram Community post:
The above Wolfram Language code has been updated to post multipart/form-data with HTML email body and an attachment. Though URLFetch does not currently support the RFC 7578 multipart/form-data section 4.2 Content-Disposition "filename" parameter, Zach Bjornson recently published a hack that gets around this limitation. The URLFetch update uses this hack to send the attachment.
This Wolfram Community post was originally a Share an Idea comment titled: Simple inexpensive delivery service outperforms SendMail. It was written from the perspective of a small developer who sends a peak of no more than dozens of test emails per day, but who aspires to send thousands of emails per day. Though the insights offered remain valid, it seems more important to gather the emailing experiences of the larger Wolfram Community, both those currently sending email at relatively low volume and those already sending at higher volumes. Accordingly Ive turned this into an Ask a Question post: Use SendMail or an external email delivery service? I invite people to share their experiences with either Wolfram Language SendMail or with external email delivery services.