0

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    Are you using the correct port? Many ISPs block outbound Port 25 and I don't see you specify a manual port override. See here for a list of GMail SMTP endpoints you can use: https://support.google.com/a/answer/176600?hl=en – Dai Aug 16 '15 at 23:01
  • Removed my answer; I agree with @Eris, this is a duplicate. – briantist Aug 16 '15 at 23:32

0 Answers0