Ian using below PowerShell to send email test work form wins10 but form windows server2016 it wont works
$Username = "XXX@XXX.com"
$EmailPassword = "XXX"
$Attachment= "D:\test\test.txt"
$EmailTo = "YYY@YYY.com"
$EmailFrom = "XXX@XXX.com"
$Subject = "PowershellTest"
$Body= "PowershellTest"
$SMTPServer = "smtp.office365.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom, $EmailTo, $Subject, $Body)
$Attachment = New-Object System.Net.Mail.Attachment($Attachment)
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $EmailPassword)
$SMTPClient.Send($SMTPMessage)
I got below error
Exception calling "Send" with "1" argument(s): "Failure sending mail."
At line:15 char:1
+ $SMTPClient.Send($SMTPMessage)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SmtpException
I idea
Thanks
Issue solved it looks that this function does not support TLS 1.2 I enable TL 1.0 and it works normally
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.