sending emails through Matlab

31 ビュー (過去 30 日間)
Lalitha Srilal Kannangara Arachchige
コメント済み: Omar Salah 2021 年 8 月 5 日
I have tried with following code.
mail = 'my_email@gmail.com';
password = 'my_password';
setpref('Internet','SMTP_Server','smtp.gmail.com');
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.starttls.enable','true');
%props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
%props.setProperty('mail.smtp.socketFactory.port','25');
sendmail(sent_email,'Test from MATLAB','Hello! This is a test from MATLAB!')
But it gives the following error after allowing access to the low-security application through Gmail account.
"Error using sendmail (line 175)
Could not connect to SMTP host: smtp.gmail.com, port: 25, response: 421"
can anyone help me to solve this issue?

回答 (1 件)

Kojiro Saito
Kojiro Saito 2018 年 7 月 9 日
As this page says, smtp.gmail.com uses port 465 (SSL) or 587 (TLS), so you need to specify port number.
props.setProperty('mail.smtp.socketFactory.port','465');
Also, by default, Gmail blocks less secure apps, so you need to enable it following the steps in this page. If you have Google accounts on your own, a simple way is enabling less secure apps from https://myaccount.google.com/lesssecureapps.
  1 件のコメント
Omar Salah
Omar Salah 2021 年 8 月 5 日
This worked for me. Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by