sending mail from gmail using sendmail()

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 commentaires

Luna
Luna le 29 Mai 2019
Does it give any error message?
Adam Danz
Adam Danz le 29 Mai 2019
Check for interference with your antivirus program(s) and firewalls. These are common problems (see comments in that link).
Iddo Weiner
Iddo Weiner le 31 Mai 2019
Sorry for not posting the error message initially. Here it is:
Error using sendmail (line 175)
Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection refused: connect
Iddo Weiner
Iddo Weiner le 31 Mai 2019
Adam - thanks a lot! It was indeed the anti-virus :))
Thanks
Adam Danz
Adam Danz le 31 Mai 2019
Great! I copied my comment as an answer so your question is categorizes as answered.
Abolfazl Nejatian
Abolfazl Nejatian le 29 Avr 2021
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 le 29 Avr 2021
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

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 31 Mai 2019
Modifié(e) : Adam Danz le 1 Juin 2019

0 votes

Check for interference with your antivirus program(s) and firewalls. These are common problems (see comments in that link).

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by