Settings required to use sendmail with an outlook account?
조회 수: 19 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Daniel LaCroix
2015년 12월 6일
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
Markus Hohlagschwandtner
2022년 11월 26일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Web Services에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!