Message Boards Message Boards

Send email with SendMail or an external delivery service?

8 Replies

Yes, all mail services will handle HTML formatted email. For a simple Mailgun example see Manual > Sending Messages > Sending via API. The example cURL HTML string is added to the MultipartElements option of the Wolfram Language URLFetch. Preserve and enhance the reputation of your domain (and IP address) by sending both text and HTML or text only, see Email Best Practices > Email Content.

Whether it's better to use SendMail or an email delivery service will depend on your application. Right now the delivery service is likely the only solution if you need to send thousands of emails per month, anticipate even higher future volumes, and want to send from your own domain to many different destination email addresses. I heartily agree with your suggestion to enhance SendMail. Indeed there could be quite an opportunity for a strategic alliance between Wolfram Research and an email delivery service provider: Wolfram would gain highly specialized expertise in delivering email against the ever evolving background of spammers and countermeasures. The delivery service provider might gain a lot of new users from Mathematica and Wolfram Cloud applications.

I'm working in an implementation of Mailgun API for Mathematica. Just to leave a note for future readers, I discovered that Base64 are not supported in Gmail and Outlook, as you can check here.

POSTED BY: Rodrigo Murta

Christopher, thanks for sharing. If I am not mistaken this adds html formatted mail.

Posted 10 years ago

If it is better, why wouldn't SendMail[] be modified to work like this?

POSTED BY: Sandu Ursu

The following URLFetch must be almost right. the error message is

 { "message": "'from' parameter is missing"}

This is the command used:

URLFetch["https://api.mailgun.net/v3/sandboxYOURID.mailgun.org/\
 "Parameters" -> 
  {
   "from" -> "Mailgun Sandbox<postmaster@sandboxYOURID.mailgun.org>",
   mailname<emailaddress>",
   "subject" -> "Hello",
   "text" -> "Congratulations message has been send",
   "html" -> 
    "<html> <center> HTML version of the body <img src='cid:pdfpicture.jpg'></center></html>"
   },
 "MultipartData" -> {{"inline", "multipart/form-data" , Import["pdfpicture.jpg", "Byte"]} },
 (*"JSON", *)
 "Method" -> "POST", 
 "Username" -> "api",
 "Password" -> "key-YOURKEY"
 ]

If I use getpostman.com to check my API command it works fine. There must be a syntax error in my URLFetch lines.

note: in mma9 "MultipartData" was used in mma10.1 use "MultipartElements"

Pieter van Bijnen points out the importance of sending email in HTML format and including inline images. Accordingly, I’ve updated the code in my original post to demonstrate such an email.

Also, don’t delay setting up your own email domain. The code in my original post sends an email from the Mailgun sandbox domain. But all your test, development, and production code should send email from your own domain. Domain setup consists of two simple steps. First, generate DNS zone file TXT, CNAME, and MX records: login to Mailgun (or whichever email delivery service you’ve chosen), follow the link to add a new domain, and enter a subdomain name. Second, enter these records into the DNS zone file for your domain: login to your domain hosting account and follow the appropriate links to add zone file records. Other than entering these records, subdomain setup does not involve any other actions on the domain hosting account. If you’re building applications that do both bulk marketing and transactional email, then keep their email reputations separate by setting up different email domains for each.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract