Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

Send-MailMessage Unable to Read Data From the Transport Connection

December 18, 2022
in Blog, Microsoft 365, Powershell
0
ADVERTISEMENT

Table of Contents

Sending emails through Microsoft 365 with PowerShell

We are using the PowerShell to send emails using Microsoft 365 SMTP:

Send-MailMessage `
    -To "[email protected]" `
    -From "[email protected]" `
    -Subject "This is a test message from PowerShell" `
    -Body "Hello World!" `
    -Credential $Cred `
    -SmtpServer "smtp.office365.com" -Port 587 -UseSsl

The above command works fine in our test Windows 10 computer, but when we use it on our Windows servers, the code fails with an SmtpException Failure sending mail, Unable to read data from the transport connection: net_io_connectionclosed.

Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed.

At line:1 char:1
+ Send-MailMessage `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

Enable TLS 1.2 on Windows Server

The matter is that the Microsoft 365 SMTP servers accept only TLS 1.2 for negotiating STARTTLS. 

So, to use TLS 1.2 for connections to the email server from the PowerShell console, we must add the following command before executing the Send-MailMessage cmdlet:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Send-MailMessage `
    -To "[email protected]" `
    -From "[email protected]" `
    -Subject "This is a test message from PowerShell" `
    -Body "Hello World!" `
    -Credential $Cred `
    -SmtpServer "smtp.office365.com" -Port 587 -UseSsl

Now, the PowerShell script works without any error. 

Send-MailMessage Unable to Read Data From the Transport Connection

But it is inconvenient because:

  • You must add the code before any Send-MailMessage command.
  • The command only made the current PowerShell session using TLS 1.2. When you restart your server or open another PowerShell session. The issue will happened again.

So, we need to enable TLS 1.2 on our server permanently. Then even we restart your computer or restart the PowerShell session the script would work without insert any addition command.

To enable TLS 1.2 on Windows Server, simply copy/paste below commands into an elevated PowerShell then execute them at once.

Set-ItemProperty `
    -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' `
    -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

Set-ItemProperty `
    -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' `
    -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

Below is a screenshot when we are enabling TLS 1.2 on our Windows Server 2016.

How to Fix Unable to Install NuGet Provider in PowerShell

After enabled the TLS 1.2 on our Windows Server. We ran the below command to check if it works.

[Net.ServicePointManager]::SecurityProtocol
How to Fix Unable to Install NuGet Provider in PowerShell

Finally, restart the PowerShell session then trying to send email using PowerShell. You should be able send email without an error or problem.

ADVERTISEMENT
5/5 - (1 vote)
Previous Post

The Server Response was 5.7.3 STARTTLS is Required to Send Mail

Next Post

How to Fix Unable to Install NuGet Provider in PowerShell

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory