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?
8 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(3 个)
Manoj Das
2015-6-20
编辑:Walter Roberson
2015-6-20
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 个评论
SuperNano
2015-11-5
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
2016-3-31
@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!
Image Analyst
2015-3-11
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!