I am trying to send the mail from PowerShell.
$EmailFrom = "[email protected]" $EmailTo = "[email protected]" $Subject = "Subject" $Body = "Body" $filenameAndPath = "C:\Desktop\EE.txt" $SMTPServer = "smtp.gmail.com" $SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom, $EmailTo, $Subject, $Body) $attachment = New-Object System.Net.Mail.Attachment($filenameAndPath) $SMTPMessage.Attachments.Add($attachment) $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "password"); $SMTPClient.Send($SMTPMessage) When I run this code I get the following exception:
Exception calling "Send" with "1" argument(s): "Failure sending mail." At line:13 char:1 + $SMTPClient.Send($SMTPMessage) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SmtpException
How can I make $SMTPClient.Send() work correctly?