Settings required to use sendmail with an outlook account?

44 views (last 30 days)
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 = '';
password = 'password';
props = java.lang.System.getProperties;
% 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.starttls.enable', 'true' ); %was recommended for the ports 587 and 25
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)
When using port 465, I get the error:
Error using sendmail (line 172)
Could not connect to SMTP host:, port: 465;
Connection timed out: connect
Error in testmail (line 15)
sendmail('','asdf','adsf') 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!

Answers (1)

Daniel LaCroix
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.
Also, if you want to use Outlook, there seems to be a specific solution for that. See this link.
  1 Comment
Markus Hohlagschwandtner
Markus Hohlagschwandtner on 26 Nov 2022
Try this:
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.socketFactory.class', '');
props.setProperty( '', smtpServer);
props.setProperty('mail.smtp.user', smtpUser);
props.setProperty('mail.smtp.password', smtpPassword);
props.setProperty('', 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);
sendmail('','MURR System anomaly detection', mailbody);
catch ME

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!