how to use sendmail with office365 email account
8 次查看(过去 30 天)
显示 更早的评论
I failed to use sendmail in combination with an office365 account.
I used the code below:
smtp = 'smtp.office365.com';
port = '587';
user = 'myusername@something.com';
psswd = 'mypassword';
emailto = 'someaddress@something.com';
subject = 'test';
text = 'test';
setpref( 'Internet', 'SMTP_Server', smtp );
setpref( 'Internet', 'SMTP_Username', user );
setpref( 'Internet', 'SMTP_Password', psswd );
props = java.lang.System.getProperties;
props.setProperty( 'mail.smtp.user', user );
props.setProperty( 'mail.smtp.host', host );
props.setProperty( 'mail.smtp.port', port );
props.setProperty('mail.smtp.auth', 'true');
props.setProperty('mail.smtp.starttls.enable', 'true');
props.setProperty('mail.smtp.socketFactory.port', port);
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
sendmail(emailto , subject, text);
It gives this error:
Error using sendmail (line 172)
Could not connect to SMTP host: smtp.office365.com, port: 587;
Connection refused: connect
Note that with the same code I have managed to send an email using a gmail account (using server:smtp.gmail.com and port:465)
Is it something I can fix via matlab or is it an office365 specific problem ?
matlab version: Matlab R2013b
1 个评论
Markus Hohlagschwandtner
2022-11-26
My solution was this line:
props.setProperty('mail.smtp.auth', 'false');
回答(2 个)
另请参阅
类别
在 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!