Sent Email alert from MATLAB

时间:2016-04-04 17:36:47

标签: matlab email smtp

I need to send email alert from my MATLAB program. I used below code to do that. But it is giving an error. How can I fix it?

function recipient = matlabmail(recipient, message, subject, sender, psswd)

if nargin<4
    sender = 'mysender@gmail.com';
    psswd = 'password';
end

setpref('Internet','E_mail',sender);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',sender);
setpref('Internet','SMTP_Password',psswd);

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('receive@gmail.com', 'Send Mail from Matlab', 'Hi from MATLAB');

This is the error massage I got:

email 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

Error in email (line 42) sendmail('receive@gmail.com', 'Send Mail from Matlab', 'Hi from MATLAB');

2 个答案:

答案 0 :(得分:1)

如错误所示:它找不到任何证书(连接是可信的)。

检查这个问题,我确信其中一个解决方案对您来说已足够(忽略或添加证书):

How to ignore PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException?

答案 1 :(得分:0)

当我允许不太安全的应用访问我的帐户时,我获得了成功。转到&#34;不太安全的应用&#34;我的帐户中的部分。 &#34;访问不太安全的应用,&#34;选择开启。 此外,我必须关闭我的防病毒软件。