Author Posts

December 26, 2017 at 2:19 pm


I get this error when trying to send a mail via powershell.

Here is my script:

$To= ""
$From = ""
$Subject  = "Salutation"
$SMTPServer = ""
$SMTPPort = "465"
$body = "test message"
$mdp = "toto"
$PWord = ConvertTo-SecureString –String $mdp –AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($From, $PWord)
$SMTPClient.EnableSsl = $true
Send-MailMessage -To $To -From $From -Subject $Subject -SmtpServer $SMTPServer -Body $body -Credential $Credential  -Port $SMTPPort 

Here is the error i got:

Send-MailMessage : Impossible de lire les données de la connexion de transport : net_io_connectionclosed.
Au caractère Ligne:11 : 1
+ Send-MailMessage -To $To -From $From -Subject $Subject -SmtpServer $S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

Thank's for your help.

December 26, 2017 at 10:03 pm

Are you able to test connectivity to and is that successful.

Test-NetConnection -Port 465 -ComputerName -InformationLevel Detailed

December 26, 2017 at 11:28 pm

As mentioned above first try Test-NetConnection. If this passes. Then ensure assuming your gmail account is a free account that the gmail account you are trying to send has not reached the maximum send limit, I believe its maximum 2000 messages per day. The Error message net_io_connectionclosed is pretty generic and doesn't directly show what the underlying issue is. if you want to dig deep a wireshark packet capture would give you a better idea whats happening

alternatively you can try the below with the -useSSL switch and port changed to 587

$To= ""
$From = ""
$Subject  = "Salutation"
$SMTPServer = ""
$SMTPPort = "587"
$body = "test message"
$mdp = "toto"
$PWord = ConvertTo-SecureString –String $mdp –AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($From, $PWord)
Send-MailMessage -To $To -From $From -Subject $Subject -SmtpServer $SMTPServer -Body $body -Credential $Credential  -Port $SMTPPort -UseSsl

hope this helps

December 27, 2017 at 1:10 am

There are some issues in your code.
See this article for details:

December 27, 2017 at 2:40 pm


Here is the informations I get

ComputerName             :
RemoteAddress            :
RemotePort               : 465
AllNameResolutionResults : 2a00:1450:400c:c04::6c
MatchingIPsecRules       : 
NetworkIsolationContext  : Internet
InterfaceAlias           : Wi-Fi
SourceAddress            : MyIP
NetRoute (NextHop)       : MyIP
PingSucceeded            : True
PingReplyDetails (RTT)   : 18 ms
TcpTestSucceeded         : True