Table of Contents
When sending emails from various applications or scripts, you may encounter error 5.7.3 StartTLS is Required to Send Email. You may face this error in different apps (SQL Server, Jenkins), scripts, and programming languages (Visual Basic, PowerShell, Python, Java, C#).
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
In our case, we saw an error Send-MailMessage : Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [DM6PR06CA0054.namprd06.prod.outlook.com] when we are sending an email from Exchange Online (Microsoft 365):
Send-MailMessage : Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail
[DM6PR06CA0054.namprd06.prod.outlook.com]
At line:1 char:1
+ Send-MailMessage `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient), SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage.
What Does the StartTLS is Required Error Mean?
StartTLS is an extension of the SMTP protocol that allows telling the email server that the email client wants to use a secure connection using TLS or SSL. When using STARTTLS, an encrypted connection is created right on top of a usual TCP connection instead of opening a separate port for encrypted connections. The StartTLS command is used by both SMTP and IMAP (POP3 uses a different STLS command for encryption).
In order to check that your email server supports StartTLS, open a command prompt and connect to it using telnet command.
telnet smtp.office365.com 587
In this example, the client has requested (EHLO) a list of features that the email server supports, and the server has returned that it can use STARTTLS: 250-STARTTLS.
250-SG2PR02CA0114.outlook.office365.com Hello [2405:4802:336:17e0:4037:bbbc:534e:a14a]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
Most SMTP servers implement STARTTLS only on port 587. Some servers (like Gmail) also allow to use STARTTLS on default SMTP port 25.
5.7.3 STARTTLS is Required to Send Mail PowerShell
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
As you can see, the error was gone, and the email was sent to admin’s mailbox.