Normally, to send mail by Mathematica, I use something like this:

       "From"->"[email protected]",

So I can call it like:

sendMail["my subject","my body"]

It used to work so far so good, but now I started to receive this error message:

"SendMail::authfail: Login credentials were denied by the server "smtp.gmail.com"." And received this mail from Google.

enter image description here

If I just try do give permission to "less secure app", I get this message:

enter image description here

How can I use SendMail with this new security rule?

I'll send a mail to Wolfram support too. If I get something I post here.

  • $\begingroup$ SendMail uses SMTP, and as far as I see, that protocol is under the "less secure apps" yet. $\endgroup$
    – FJRA
    Dec 1, 2014 at 20:23
  • $\begingroup$ @FJRA, I just had to go through the Google less secure app to mail from iphone with smtp.gmail.com works. $\endgroup$ Dec 2, 2014 at 0:22
  • 3
    $\begingroup$ If your are using Google's two way authentication you probably need an app specific password. $\endgroup$ Dec 2, 2014 at 7:27
  • $\begingroup$ I confirm what Sjoerd said about app specific password, it just worked for me. $\endgroup$
    – faysou
    May 15, 2015 at 22:39
  • $\begingroup$ I just set up SendMail in v11. I agree, follow @SjoerdC.deVries link to make an application specific password that you include in your SendMail or SetOptions per the Wolfram page under Scope/Account Configuration ... I also needed to the elect StartTLS as the encryption protocol and used the port listed for StartTLS on this gmail help page. I also (kept) IMAP 'on ' under gmail Settings / Forwarding and POP/IMAP. $\endgroup$
    – PlaysDice
    Sep 13, 2016 at 23:12

2 Answers 2


If you are regularly sending email back and forth to a small number of people, then SendMail with the Google “less secure apps” setting is a very good solution. On the other hand, if you send or aspire to send, a large number of transactional or marketing emails every day, then an email delivery service may give a much better delivery success rate. For example, to send a test message through the Mailgun service, sign up for their free account and sandbox domain and make a URLFetch call to the API:

   "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!"},

Update 12/4/15:

In its original version this answer advocated an email delivery service over SendMail because at that time SendMail didn’t seem to be a good option from the Wolfram Cloud, for example, emails would only come from the Wolfram domain. It now turns out that a private cloud eliminates this issue as well as offers other advantages. For further details on calling the Mailgun API, see Wolfram Community question Send email with SendMail or an external delivery service?.

  • $\begingroup$ Tks, I'll check it. +1 $\endgroup$
    – Murta
    Mar 30, 2015 at 21:10
  • 2
    $\begingroup$ Welcome to StackExchange and thank you for posting a useful answer. On StackExchange, users are encouraged to write self contained answers instead of simply giving links to the full description. While not always possible, it's best to include all details in the post. What if the site you are linking to disappears or simply changes its URL? While W|C unlikely to go away, they might easily change the URL structure which would make the link invalid and make this answer much harder to follow. $\endgroup$
    – Szabolcs
    Mar 31, 2015 at 20:36
  • $\begingroup$ @Szabolcs thank you for your welcome message! In the past few months I've done more work with the Mailgun email delivery service, which necessitated an update of the Wolfram Community post on this topic. Today I've also updated this post making it more self contained, but I kept the link because the lengthy Wolfram Community post goes into some less essential though still important details. I look forward to any further suggestions that you might have. $\endgroup$ Dec 4, 2015 at 20:27

If you have activated the two-step verification in gmail, you need to use an password dedicated to one application. This works straightforwardly. From https://support.google.com/accounts/answer/185833:

Visit your App passwords page. You may be asked to sign in to your Google Account. At the bottom, click Select app and choose the app you’re using. Click Select device and choose the device you’re using. Select Generate. Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device. Select Done.

Once you are finished, you won’t see that App password code again. However, you will see a list of apps and devices you’ve created App passwords for.

You just need to enter the 16-digit password in the Password method of SendMail.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.