VeeamHub/powershell

Support for TLS in SMTP server

Closed this issue · 2 comments

clowg commented

Is your script able to support TLS for the SMTP server?
I want to send via smtp.office365.com and that gives this error:

10/07/2023 17:11:32 - [ERROR] Send-MailMessage : Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [SYBPR01CA0209.ausprd01.prod.outlook.com 
2023-07-10T05:11:31.967Z 08DB7C994F8AAD26]
At C:\Reports\BR-MorningReport.ps1:225 char:5
+     Send-MailMessage -From $mail_From `
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

Hi @clowg,

The script you referenced uses the cmdlet Send-MailMessage to send email which is found at line 225. As it's a Microsoft PowerShell cmdlet, I recommend checking their documentation:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-5.1

Hint: You need to add the UseSsl and, most likely, the Port parameters for the cmdlet to support TLS.

clowg commented

Thanks for the hint.
Got it all working using stored credentials and SSL.