Configuring Mathematica to send email from a notebook

This might not work for you but is an example to use the Gmail mail server to send emails from a notebook.

The example code overrides all settings in the MMa email preference settings and should work out of the box. NB I have tested this only on my Mac.

SendMail[
 "To" -> "[email protected]",
 "Subject" -> "Example Message",
 "Body" -> "My text",
 "From" -> "[email protected]",
 "Server" -> "smtp.gmail.com",
 "UserName" -> "[email protected]",
 "Password" -> Automatic,
 "PortNumber" -> 587,
 "EncryptionProtocol" -> "StartTLS"
 ]

The challenge with SendMail is that you the Mathematica user must attempt to make the ISP mail server happy. For example, Matariki’s above Gmail solution depends on properly setting up Allowing less secure apps to access your account. An email delivery service such as Mailgun offers a simpler solution, see my Wolfram Community post Simple inexpensive delivery service outperforms SendMail. The posted example calls CloudDeploy, but you would just be calling the enclosed URLExecute directly from Mathematica.


I have gotten mail to work through Microsoft Exchange 365 using code similar to the gmail code above.

SendMail["To" -> "[email protected]", 
 "Subject" -> "Example Message via Microsoft", "Body" -> "Keine Fehler!", 
 "From" -> "[email protected]", "Server" -> "outlook.office365.com",
  "UserName" -> "[email protected]", "Password" -> Automatic, 
 "PortNumber" -> 587, "EncryptionProtocol" -> "StartTLS"]

You can include your actual password instead of Automatic for the password field. For some reason, I was not able to get this to work by filling out the server fields in the mail preferences dialog; they need to be specified with each message.

Further, as far as I can tell, Mathematica ignores the "From" and "Full Name" fields. Whatever server I use (gmail, outlook, Wolfram Cloud), it inserts the UserName instead.