sending emails through Matlab
31 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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.
参考
カテゴリ
Help Center および File Exchange で Web Services についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!