Send-MailMessage failing

Causemaker, Andi 0 Reputation points
2024-03-26T19:21:02.2366667+00:00

I am trying to use "Send-MailMessage" to test my smtp connectivity to an SMTP server. The 'client' in question is Windows Server 2022 Datacenter. I am getting the error message:

Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed.
At line:1 char:1
+ Send-MailMessage -from <source.server@domain.com> -to <my.email@domain.com> ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

I have verified that the traffic is NOT being blocked by our firewall. Other servers in the same subnet are able to send mail using the same SMTP host (exact same command) without any error.

Is there some configuration on the client that I'm missing? or is there something on the server that could be blocking a single IP/host from being able to send?

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,384 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 46,711 Reputation points
    2024-03-26T19:40:07.7933333+00:00

    Can we assume that you're using SSL? If that's the case it may be that the client is using an unsupported version of TLS.

    Try this: [System.Net.ServicePointManager]::SecurityProtocol = 'TLS12' before the Send-MailMessage.

    If that doesn't work, try "TLS13".

    Also, are you authenticating (i.e., providing a credential) with Send-MailMessage? Are you using a client (587) or server port (25)?

    What you've missed is providing a code snippet that details your usage of the Send-MailMessage cmdlet. Without that one can only guess at the source of your problem.

    0 comments No comments

  2. Causemaker, Andi 0 Reputation points
    2024-03-26T19:51:32.8433333+00:00

    Hello, sorry I should have provided more details.

    Nope, no SSL, No credentials/authentication. Just plain SMTP on port 25. It works from every other server I've tested it from but this ONE.

    Here's the command I'm using. I can literally copy/paste this same command on multiple servers, and all will send the message successfully except this one server:

    Send-MailMessage -from servername@domain.com -to my.email@domain.com -subject "smtp test" -SmtpServer smtp.domain.com


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.