Settings required to use sendmail with an outlook account?
19 views (last 30 days)
Show older comments
I am having problems configuring matlab to send an email using an Outlook smtp server.
I've had luck before with a gmail account but haven't gotten Outlook to work. I am trying to email information now that I would prefer not to send via gmail etc.
Code that I've tried to get to work:
mailfrom = 'email@domain.com';
password = 'password';
setpref('Internet','E_mail',mailfrom);
setpref('Internet','SMTP_Server','smtp-mail.outlook.com');
setpref('Internet','SMTP_Username',mailfrom);
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.remove('mail.smtp.socketFactory.class'); %Some recommendations included commenting out the line above and using this line instead to remove the SSL ...?
%
props.setProperty('mail.smtp.port','587'); %have tried this line, and the below line, and both, with ports 465, 587, and 25. Port 465 works with google.
%
props.setProperty('mail.smtp.socketFactory.port','587');
props.setProperty('mail.smtp.starttls.enable', 'true' ); %was recommended for the ports 587 and 25
sendmail('asdf@asdf.com','asdf','adsf')
When I use ports 587 or 25, I get the error:
Error using sendmail (line 172)
Exception reading response;
Unrecognized SSL message, plaintext connection?
Error in testmail (line 15)
sendmail('asfd@asdf.com','asdf','adsf')
When using port 465, I get the error:
Error using sendmail (line 172)
Could not connect to SMTP host:
smtp-mail.outlook.com, port: 465;
Connection timed out: connect
Error in testmail (line 15)
sendmail('asdf@asdf.com','asdf','adsf')
...so it looks like outlook doesn't accept 465 as a connection, but somehow I'm not using port 25 or 587 correctly... even with the command intended to start SSL.
Apologies for the rookie question!
0 Comments
Answers (1)
Daniel LaCroix
on 6 Dec 2015
Ah, the adventures of sending email through MATLAB. I'm sort of inexperienced in MATLAB myself, but I've spent plenty of time trying to send email.
It looks like the error might be coming from the second to last line. It has starttls on, but the error is about SSL, so maybe the problem is there. You're comment says that line was recommended, not required, so try commenting that out and see if that helps.
1 Comment
Markus Hohlagschwandtner
on 26 Nov 2022
Try this:
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.remove('mail.smtp.socketFactory.class');
props.setProperty( 'mail.smtp.ssl.trust', smtpServer);
props.setProperty('mail.smtp.user', smtpUser);
props.setProperty('mail.smtp.password', smtpPassword);
props.setProperty('mail.smtp.host', smtpServer);
props.setProperty('mail.smtp.port', smtpServerPort);
props.setProperty('mail.smtp.auth', 'false');
props.setProperty('mail.smtp.starttls.enable', 'true');
props.setProperty('mail.smtp.socketFactory.port', smtpServerPort);
setpref('Internet','SMTP_Server',smtpServer);
setpref('Internet','SMTP_Username',smtpUser);
setpref('Internet','SMTP_Password',smtpPassword);
setpref('Internet','E_mail',smtpUser);
try
sendmail('hohla@fotec.at','MURR System anomaly detection', mailbody);
catch ME
ME.message
%ME.cause
%ME.Correction
end
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!