Receiving an error whilst attempting to use 'sendmail'

5 views (last 30 days)
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
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.
Joel Bradshaw
Joel Bradshaw on 3 Dec 2015
Edited: Joel Bradshaw on 3 Dec 2015
2015a is at home on my private laptop. 2013b is via a remote desktop to my office pc. Yes this was the problem. On my home network avast internet security was blocking the outgoing email. Thank you very much although I'm not sure how I can extend this to my office pc. :)

Sign in to comment.

Answers (2)

Joel Bradshaw
Joel Bradshaw on 3 Dec 2015
Thanks to 'Image analyst' I have solved the first issue when using R2015a on my home network. The firewall was blocking the outgoing email when I attempted to send.
Unfortunately if this is the same issue for R2013b (my office network) then the solution will require my contacting IT.

prince tiwari
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

Products

Community Treasure Hunt

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

Start Hunting!