how to use sendmail with office365 email account

9 visualizaciones (últimos 30 días)
Laury Renac
Laury Renac el 19 de Oct. de 2017
Comentada: Markus Hohlagschwandtner el 26 de Nov. de 2022
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 comentario
Markus Hohlagschwandtner
Markus Hohlagschwandtner el 26 de Nov. de 2022
My solution was this line:
props.setProperty('mail.smtp.auth', 'false');

Iniciar sesión para comentar.

Respuestas (2)

Tobias Riedener
Tobias Riedener el 8 de Mzo. de 2018
What happened to this problem?? Looking into exactly the same...

Josh Stoller
Josh Stoller el 9 de Feb. de 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