how to use sendmail with office365 email account
9 views (last 30 days)
Show older comments
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 Comment
Markus Hohlagschwandtner
on 26 Nov 2022
My solution was this line:
props.setProperty('mail.smtp.auth', 'false');
Answers (2)
Tobias Riedener
on 8 Mar 2018
What happened to this problem?? Looking into exactly the same...
0 Comments
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!