MATLAB Answers

Sendmail authentication error with gmail

96 views (last 30 days)
Erin on 8 Jul 2015
Commented: Shae Morgan on 8 Oct 2020
Here is my code:
myaddress = '';
mypassword = 'example';
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.socketFactory.class', ...
sendmail(,'email subject test',...
'this email is a test','D:\testimagetosend.tif')
And here is the error message: Error using sendmail (line 171) Authentication failed.
From everything else I have read, the preferences and properties required for gmail are all taken care of, but still getting the error.


Show 2 older comments
Bruno Rango
Bruno Rango on 7 Jul 2016
I've also gotten the same authentication error. To fix it, allow Gmail to get acces from less secure apps. To do this, click turn on in the following link:
It worked for me, so I hope it helps.
Kind regards.
Bruno R
Manikandan Prabakaran
Manikandan Prabakaran on 13 Sep 2018
Mr.Bruno's solution works fine. Thanks a lot sir.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 8 Aug 2015
Within the last 8 months, Google turned off default support for an older less-secure authentication. You can re-enable it on your account... for now.


Ella on 23 Nov 2015
Awesome Thank you for sharing the solution
Irene arnaldo
Irene arnaldo on 6 Aug 2019
I am still having problems with authentication failed!!
A) I have disabled 2 step verification, turned on 'less secure apps' and introduce used my normal password on matlab code: didnt work.
B) I also tried getting the app password but matlab doesn´t recognize it (Do you need to verify it somehow thrugh matlab???).
Shae Morgan
Shae Morgan on 8 Oct 2020
I'd like to add that if your use seems suspicious to google, it'll still fail the authentication attempt as suspicious activity.
Not sure how to work around this.

Sign in to comment.

Pankaj on 14 Apr 2016
Edited: Pankaj on 14 Apr 2016
For some service providers the extension '' in myaddress may cause authentication error. Simply use userID.


Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!