how to use sendmail with office365 email account

9 vues (au cours des 30 derniers jours)
Laury Renac
Laury Renac le 19 Oct 2017
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 commentaire
Markus Hohlagschwandtner
Markus Hohlagschwandtner le 26 Nov 2022
My solution was this line:
props.setProperty('mail.smtp.auth', 'false');

Connectez-vous pour commenter.

Réponses (2)

Tobias Riedener
Tobias Riedener le 8 Mar 2018
What happened to this problem?? Looking into exactly the same...

Josh Stoller
Josh Stoller le 9 Fév 2022
You do not have anthing for the var "host"

Community Treasure Hunt

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

Start Hunting!

Translated by