Receiving an error whilst attempting to use 'sendmail'

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

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 2015년 12월 3일
편집: Joel Bradshaw 2015년 12월 3일
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. :)

댓글을 달려면 로그인하십시오.

답변 (2개)

Joel Bradshaw
Joel Bradshaw 2015년 12월 3일

0 개 추천

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 2016년 3월 26일

0 개 추천

Error using sendmail (line 171) Could not connect to SMTP host: smtp.gmail.com, port: 25; Connection timed out: connect please solve my problem

제품

태그

질문:

2015년 12월 3일

답변:

2016년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by