Below is the code snippet used to send mail. which worked until recently and is giving “Failure sending mail." Error. (Version: 5.1.16299.98)
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = " "
$Password = " "
$to = " "
$cc = " "
$subject = "AUTOMATED "
$message = New-Object System.Net.Mail.MailMessage
$message.Subject = $subject
$message.To.Add($to)
$message.Cc.Add($cc)
$message.From = $username
$message.IsBodyHtml = $true
$message.Body =
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username,$Password);
$smtp.Send($message)
Write-Host "Mail Sent"
The error is:
Exception calling "Send" with "1" argument(s): "Failure sending mail." At F:\powershell_scripts\xxx.ps1 :88 char:1 + $smtp.Send($message) + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SmtpException
tial($Username, $Password);
(I am assuming this happened while pasting code to stackoverflow) – ClumsyPuffin$smtp.EnableSSL = $true. tial($Username, $Password);
makes no sense. Something is missing. Is it a copy-paste error? Are you actually running it in ISE? – vonPryz