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!