필터 지우기
필터 지우기

sending mail from gmail using sendmail()

조회 수: 13 (최근 30일)
Iddo Weiner
Iddo Weiner 2019년 5월 29일
댓글: Adam Danz 2021년 4월 29일
Hi,
This code below used to work for me in the past (~2 years ago), but now it doesn't. Any ideas why?
Has something changed in Google's settings? Or in MATLAB?
I can tell you that my less secure apps are enabled on gmail - so that's not the problem.
Thanks, Iddo
% parameters
mail = 'myUsername@gmail.com'; % my gmail address
password = 'myPassword'; % my gmail password
host = 'smtp.gmail.com';
sendto = 'someone@somewhere.com';
Subject = 'test subject';
Message = 'test message';
% 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');
% execute
sendmail(sendto,Subject,Message)
  댓글 수: 7
Abolfazl Nejatian
Abolfazl Nejatian 2021년 4월 29일
i used your codes and replace my information but the problem is
Error using sendmail (line 175)
Authentication failed.
Error in Untitled (line 19)
sendmail(sendto,Subject,Message)
any solution?
Adam Danz
Adam Danz 2021년 4월 29일
This appears to be a java based error. I can only suggest to go through the trouble shooting steps discussed in the comment section of the link I provided in my answer (open the link, read through the comments under the answer).
Common problems are
  • Not setting up gmail correctly
  • firewall
  • antivirus programs

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 5월 31일
편집: Adam Danz 2019년 6월 1일
Check for interference with your antivirus program(s) and firewalls. These are common problems (see comments in that link).

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by