1

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');

Shani
  • 89
  • 8

2 Answers2

1

As the error says: It does not find any certificate (that the connection is trusted).

Check this question, I am sure that one of the solutions will be sufficient for you (ignoring or adding a certificate):

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

Community
  • 1
  • 1
DVarga
  • 21,311
  • 6
  • 55
  • 60
0

I was success when I allow less secure app access to my account. Go to the "Less secure apps" section in My Account. Next to "Access for less secure apps," select Turn on. Also I have to turn off my Antivirus software.

Shani
  • 89
  • 8