MATLAB Answers

Erin
0

Sendmail authentication error with gmail

Asked by Erin
on 8 Jul 2015
Latest activity Commented on by Irene arnaldo on 6 Aug 2019
Here is my code:
myaddress = 'example@gmail.com';
mypassword = 'example';
setpref('Internet','E_mail',myaddress);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password',mypassword);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
sendmail(toexample@cornell.edu,'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.

  5 Comments

Hi!
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:
https://www.google.com/settings/security/lesssecureapps?rfn=27&rfnc=1&asae=2&anexp=lbe-R1_C
It worked for me, so I hope it helps.
Kind regards.
Bruno R
Mr.Bruno's solution works fine. Thanks a lot sir.

Sign in to comment.

2 Answers

Answer by 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.

  2 Comments

Awesome Thank you for sharing the solution
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???).

Sign in to comment.


Answer by Pankaj
on 14 Apr 2016
Edited by Pankaj
on 14 Apr 2016

For some service providers the extension ' @gmail.com' in myaddress may cause authentication error. Simply use userID.

  0 Comments

Sign in to comment.