Group Abstract Group Abstract

Message Boards Message Boards

Send email with SendMail or an external delivery service?

8 Replies
POSTED BY: Rodrigo Murta

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.

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>",
   "to" -> "emailname<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"

Posted 11 years ago

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

POSTED BY: Sandu Ursu

Christopher,
I have tested your mail solution and it works. Then I went on trying to add "inline" html image and "attachments". Both need to be formatted like inline="@files/filename.jpg" or attachments="@files/filename.jpg". The "inline" must be very easy. I suspect the "attachment" is probably a little more difficult because it needs multipart/form-data.

in urlfetch i found "MultipartElements" -> {{"partName", "mime/type", {1, 2, 3, 4, 5}}}

can you help me solve how to do this?

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.

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

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