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