MATLAB Answers

Settings required to use sendmail with an outlook account?

51 views (last 30 days)
Matthew
Matthew on 6 Dec 2015
Answered: Daniel LaCroix on 6 Dec 2015
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

Sign in to comment.

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.

  0 Comments

Sign in to comment.


Translated by