cannot send an email through matlab

Im not being able to send an email thgourh matlab.... My google account allow external applications to use it....
here is the code.... any suggestions?
------------------------------
username='myemail';
password='mypassword';
setpref('Internet', 'SMTP_Server', 'smtp.gmail.com');
setpref('Internet','E_mail',username);
setpref('Internet', 'SMTP_Username', username);
setpref('Internet', 'SMTP_Password', password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth', 'true'); % Note: 'true' as a string, not a logical value!
props.setProperty('mail.smtp.starttls.enable', 'true'); % Note: 'true' as a string, not a logical value!
props.setProperty('mail.smtp.socketFactory.port', '465'); % Note: '465' as a string, not a numeric value!
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
sendmail('another@email', 'Hello world')
------------------------------

 Respuesta aceptada

Adam Danz
Adam Danz el 3 de Mayo de 2019
Editada: Adam Danz el 3 de Mayo de 2019

0 votos

Mario, follow this demo on how to send an email from a gmail account using matlab. You're close - you just have to make some small adjustment.
Feel free to leave a comment if you get stuck.

5 comentarios

Mario Trevino
Mario Trevino el 3 de Mayo de 2019
im still getting this error msg:
Could not connect to SMTP host:
smtp.gmail.com, port: 25;
Connection refused: connect
Error in Untitled (line 49)
sendmail(destination,subj,msg);
Adam Danz
Adam Danz el 3 de Mayo de 2019
All you have to do is copy the demo in the link, fill in your email info at the top, and make sure your gmail security is turned off. That demo includes a link to instructions on how to turn off the gmail security. I and many others have used this method with success.
If you're still having problems, copy-paste your full code in the comments below but enter fake email data to protect your identity.
Mario Trevino
Mario Trevino el 3 de Mayo de 2019
Googles security turned off....
Error message:
Error using sendmail (line 171)
Could not connect to SMTP host: smtp.gmail.com, port:
25;
Connection refused: connect
Error in Untitled (line 49)
sendmail(destination,subj,msg);
--------------------------
% User input
source = 'xxxxx8@gmail.com'; %from address (gmail)
destination = 'yyyyy@hotmail.com'; %to address (any mail service)
myEmailPassword = '1234'; %the password to the 'from' account
subj = 'This is the subject line of the email'; % subject line
msg = 'This is the main body of the email.'; % main body of email.
%set up SMTP service for Gmail
setpref('Internet','E_mail',source);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',source);
setpref('Internet','SMTP_Password',myEmailPassword);
% Gmail server.
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');
% Send the email
sendmail(destination,subj,msg);
% [Optional] Remove the preferences (for privacy reasons)
setpref('Internet','E_mail','');
setpref('Internet','SMTP_Server','''');
setpref('Internet','SMTP_Username','');
setpref('Internet','SMTP_Password','');
Mario Trevino
Mario Trevino el 3 de Mayo de 2019
OK found the problem.. it was my AVAST antivirus protection.
thank you very much!
Adam Danz
Adam Danz el 3 de Mayo de 2019
Ah, this is also a common problem. I'll update that post to mention this. Thanks for following up!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 3 de Mayo de 2019

Comentada:

el 3 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by