Anston Sorensen
Anston Sorensen

Reputation: 516

Send Email to Gmail with Batch File Using Powershell

I am trying to send an email to gmail using a batch file and I get this:

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:1 char:1
+ Send-MailMessage -SmtpServer smtp.gmail.com -port 25 -UseSsl -Credent ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
   ion
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage 

Something with authetication. I put get credentials in there though.

Batch File Code:

powershell -ExecutionPolicy ByPass -Command Send-MailMessage 
-SmtpServer smtp.gmail.com -port 25 -UseSsl 
-Credential (Get-Credential) 
-To [email protected] 
-From [email protected] 
-Subject Testing 
-Body 123

Upvotes: 1

Views: 1452

Answers (1)

Anston Sorensen
Anston Sorensen

Reputation: 516

It is very clear now. You do not need a port, it is optional. Under User Name put your email address and under password put your email password.

powershell -ExecutionPolicy ByPass -Command Send-MailMessage -SmtpServer smtp.gmail.com -UseSsl -Credential (Get-Credential) -To [email protected] -From [email protected] -Subject Testing -Body 123

Upvotes: 1

Related Questions