Receiving an error whilst attempting to use 'sendmail'
5 views (last 30 days)
Show older comments
I'm trying to use Matlab to send emails using the sendmail command. My code (taken from various other locations) is
my_default_email_address = 'email@gmail.com'; %real email removed
my_password = '******'; %real password removed
setpref('Internet','E_mail',my_default_email_address);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',my_default_email_address);
setpref('Internet','SMTP_Password',my_password);
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('recipient@live.co.uk','Test','Hello'); %real recipient removed
When I run this on R2015a I get the error:
Error using sendmail (line 171)
Exception reading response;
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
certification path to requested target
whereas in R2013b I get:
Error using sendmail (line 172)
Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection timed out: connect
I've tried changing the port from 465 to 25 and I have also allowed 'less secure apps' to access my gmail account (using the link https://support.google.com/accounts/answer/6010255?hl=en).
Please can anyone help show me what I'm doing wrong. Thanks
2 Comments
Image Analyst
on 3 Dec 2015
Is this from your home network? Or through your company or university firewall? It's possible that the firewall does not allow outgoing emails except through known protocols and programs, like in my company.
Answers (2)
prince tiwari
on 26 Mar 2016
Error using sendmail (line 171) Could not connect to SMTP host: smtp.gmail.com, port: 25; Connection timed out: connect please solve my problem
0 Comments
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!