Sendmail authentication error with gmail

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 comentarios

Alberto
Alberto el 8 de Ag. de 2015
Hi Erin,
Your code seems to be right, it is the same as mine. Maybe it is due to firewalls or from an internal settings of your OS. In my case, my code for sending emails from gmail always worked.. up to now. Now I use Windows 8 and it does not work any longer. If this is your case, then we have the same problem :(
Alberto
Alberto el 8 de Ag. de 2015
Ok, I have tried to run it on my previous machine, under WinXP, where the code always worked fine and.. now it doesn't work on WinXP neither. So, the point is then that gmail has changed its settings. At least in my case, it does not seem to be a matter of the firewalls or the OS. Something has changed on gmail in the last eight months (the last time I had to use the function).
I hope it helps you a little bit. Regards
Bruno Rango
Bruno Rango el 7 de Jul. de 2016
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
Manikandan Prabakaran
Manikandan Prabakaran el 13 de Sept. de 2018
Mr.Bruno's solution works fine. Thanks a lot sir.
machhindra bhamare
machhindra bhamare el 26 de Feb. de 2019
thanks

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 8 de Ag. de 2015

2 votos

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.

4 comentarios

Ella
Ella el 23 de Nov. de 2015
Awesome Thank you for sharing the solution
Irene arnaldo
Irene arnaldo el 6 de Ag. de 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 el 8 de Oct. de 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.
Tom
Tom el 1 de Jun. de 2022
As of March 2022 Google has disabled this completely :/

Iniciar sesión para comentar.

Pankaj
Pankaj el 14 de Abr. de 2016
Editada: Pankaj el 14 de Abr. de 2016

0 votos

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

Productos

Preguntada:

el 8 de Jul. de 2015

Comentada:

Tom
el 1 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by