I work on a server on Windows Server 2016. My aim is to send a mail using PowerShell, I wrote the script below.
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "votre objet" -SmtpServer "smtp.office365.com" -Body "Blablabla" -Credential "[email protected]" -Port "587" -UseSsl
This script works fine when I execute it on my PC, the mail is sent. So my script is OK.
When I execute it on the server I have this error "Unable to connect to the remote server". When I ping the smtp.office365.com, it is OK.
Does anyone have a idea about what is the problem?
Here the complete error:
Send-MailMessage : Impossible de se connecter au serveur distant Au caractère Ligne:1 : 1 + Send-MailMessage -From "[email protected]" -To "john.doe@myd ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
telnet smtp.office365.com 587
- it's probably blocked (you might need to install telnet client to your server if you don't have it) – Robert Dyjas"Connexion à smtp.office365.com...Impossible d’ouvrir une connexion à l’hôte, sur le port 587: Échec lors de la connexion"
(With the traduction :Unable to open a connection on the host
) – Damien K.