I am trying to send an email in PowerShell 5.0. I am using a gmail address for right now but can't successfully send the email. I'm sure it's due to username and password but I am not sure the syntax of the credentials.
send-mailmessage -to "user2 <anotheremail@gmail.com>" -from "user1 <someemail@gmail.com>" -subject "Test mail" -SmtpServer "Smtp.gmail.com" -credential "user:someemail@gmail.com password:somepassword"
This is the error I get. I x'd out any personal info:
send-mailmessage : Unable to connect to the remote server
At line:1 char:1
+ send-mailmessage -to "xxx <xxxx@gmail.com>" -from "xxxx <xxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
I don't even know if I'm using the credential parameter correctly.