0

i am trying to make a simple powershell mail sender script , but i keep getting an exception in the "Send-MailMessage " command , but i don't quite understand why .

this is the script : $Sender = "powershell121@gmail.com" $Reciever = "powershell122@gmail.com" $Subject = "testing script" $Body = " this is a mail sender powershell script , from me to me " $SMTPServer = "smtp.gmail.com" $SMTPPort = "587" Send-MailMessage -From $Sender -to $Reciever -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) ---------------------------------------------------------------------------------------- the exception i'm getting :

`      Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server
response was: 5.7.0 Authentication Required. Learn more at
At line:7 char:1
+ Send-MailMessage -From $Sender -to $Reciever -Subject $Subject `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
   ion
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
1Zixo
  • 1
  • 1
  • 1
    see: https://stackoverflow.com/questions/1252335/send-mail-via-gmail-with-powershell-v2s-send-mailmessage – Toni Nov 09 '22 at 20:48
  • Based off the error message, seems like you entered the wrong credentials. – Abraham Zinala Nov 09 '22 at 20:51
  • @Toni that's great , i wasn't aware of the adjustments i would have to make before using my gmail to send the message , thanks ♥ – 1Zixo Nov 09 '22 at 21:57
  • @AbrahamZinala the credentials are right but my email security configurations was restricted so powershell couldn't access it to send the mail , appreciate the help ♥ – 1Zixo Nov 09 '22 at 21:58

0 Answers0