sending E-mail error

39 views (last 30 days)
cem sare
cem sare on 30 Nov 2018
Commented: Ahmed bin Ali on 20 Jun 2023
Türk:
Merhaba;
MATLAB ile e-posta göndermek istiyorum ama bu kodları buldum (Sendmail kullanarak hata (satır 172)
İstisna okuma cevabı;
sun.security.validator.ValidatorException: PKIX yolu oluşturulamadı: sun.security.provider.certpath.SunCertPathBuilderException: geçerli bulunamıyor
istenen hedefe yönelik sertifika yolu
Bu hatayla karşılaştığım sorun nedir?
Teşekkürler...
English:
Hi;
I want to send e-mail with MATLAB but I found these codes (Error using sendmail (line 172)
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 )
What's the problem I'm having with this error?
Thanks...
%
% parameters
mail = 'mymail@gmail.com'; % my gmail address
password = 'mypassword'; % my gmail password
host = 'smtp.mail.com';
% preferences
setpref('Internet','SMTP_Server', host);
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',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');
% Send the email
sendmail(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')
  2 Comments
cem sare
cem sare on 30 Nov 2018
https://myaccount.google.com/lesssecureapps open and host=smtp.gmail.com
updated as but the error persists...
mark filan
mark filan on 31 Jul 2019
Enabling access for "less secure apps" means that the client/app doesn't use OAuth 2.0 . OAuth 2.0 is the industry-standard protocol for authorization. When you sign in with OAuth 2.0, you sign in to Google's system directly. In OAuth 2.0 , you authenticate directly to Gmail with your credentials and authorize an app to do certain things. The third-party app only sees an authorization token provided by Google as proof that you authenticated correctly and agreed to authorize that app.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 30 Nov 2018
Edited: Adam Danz on 4 May 2019
Here's a quick example of a demo that produces an email sent from a gmail account (specifically). Note that to send an email through your gmail account you have to turn off the app security which greatly reduces the security of your gmail account. One solution to this problem is creating a new gmail account for the sole purpose of sending emails from this script.
To turn off app security, sign into gmail and access this link: https://myaccount.google.com/lesssecureapps
[Update] See comments below regarding common problems with antivirus software and firewalls that might prevent the email from being sent.
% User input
source = 'myFakeEmail@gmail.com'; %from address (gmail)
destination = 'kofte@foobar.com'; %to address (any mail service)
myEmailPassword = 'sifre123'; %the password to the 'from' account
subj = 'This is the subject line of the email'; % subject line
msg = 'This is the main body of the email.'; % main body of email.
%set up SMTP service for Gmail
setpref('Internet','E_mail',source);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',source);
setpref('Internet','SMTP_Password',myEmailPassword);
% Gmail server.
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');
% Send the email
sendmail(destination,subj,msg);
% [Optional] Remove the preferences (for privacy reasons)
setpref('Internet','E_mail','');
setpref('Internet','SMTP_Server','''');
setpref('Internet','SMTP_Username','');
setpref('Internet','SMTP_Password','');
  11 Comments
Ahmed bin Ali
Ahmed bin Ali on 20 Jun 2023
How to use this on ThingSpeak? When ran the code this message shows up:
"send alert: This functionality is not available on remote platforms."

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!