Whenever I use the sendmail function, I get an error that reads "Error using sendmail (line 171) Authentication failed." I am pretty sure the preferences and settings are properly set up. Does anyone know how to resolve this issue?

7 views (last 30 days)
Whenever I use the sendmail function, I get an error that reads "Error using sendmail (line 171) Authentication failed." I am pretty sure the preferences and settings are properly set up. Does anyone know how to resolve this issue? I changed the settings on gmail as well for less security.

Answers (3)

Manoj Das
Manoj Das on 20 Jun 2015
Edited: Walter Roberson on 20 Jun 2015
Hello Joseph,
Here is what you do to make your sendmail command to work.. follow the below code
mail = 'my_yahoo_id@yahoo.com';
psswd = 'my_password';
host = 'smtp.mail.yahoo.com';
port = '465';
emailto = 'recepient_id@gmail.com';
m_subject = 'subject';
m_text = 'test';
setpref( 'Internet','E_mail', mail );
setpref( 'Internet', 'SMTP_Server', host );
setpref( 'Internet', 'SMTP_Username', mail );
setpref( 'Internet', 'SMTP_Password', psswd );
props = java.lang.System.getProperties;
props.setProperty( 'mail.smtp.user', mail );
props.setProperty( 'mail.smtp.host', host );
props.setProperty( 'mail.smtp.port', port );
props.setProperty( 'mail.smtp.starttls.enable', 'true' );
props.setProperty( 'mail.smtp.debug', 'true' );
props.setProperty( 'mail.smtp.auth', 'true' );
props.setProperty( 'mail.smtp.socketFactory.port', port );
props.setProperty( 'mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory' );
props.setProperty( 'mail.smtp.socketFactory.fallback', 'false' );
sendmail( emailto , 'Hello from MATLAB', 'Hello from MATLAB' );
when you open matlab you can have all these lines included in the startup script so you just have to use the sendmail command directly. Also as shown above yo ucan replace the smtp server settings accordingly for gmail by changing the smtp mail server address. The above works for MATLAB versions. In recent times I am lead to believe gmail has changed some settings since the above does not work for gmail anymore .. you still get an authentication failed error.. Hope this helps
  4 Comments
SuperNano
SuperNano on 5 Nov 2015
Thanks Image Analyst, but I found a simpler solution. Since starttls is actually a plain text protocol, if the server is using it (like the case of my uni server) there is no need to use the SSL socketFactory class. So either comment out that line or if you had already ran it (like me), use props.remove( 'mail.smtp.socketFactory.class' );
This is probably useless for most, but just in case!
Andreas
Andreas on 31 Mar 2016
@Juan not useless for me! Thanks to the above lines by Manoj and your hint of removing the SSL socketFactory class, I finally made sendmail work with the TUM / LRZ postout server. Thanks a lot!

Sign in to comment.


Christiaan
Christiaan on 10 Mar 2015
Dear Joseph,
A related post can be found here.
Kind regards, Christiaan

Image Analyst
Image Analyst on 11 Mar 2015
Try it on a different account. If that doesn't work, try it on a different computer. I have one computer, my official work computer, where I can't sent email because of some security/firewall restrictions, but on a different computer it works fine.

Community Treasure Hunt

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

Start Hunting!