send mail via powershell

Hello,

I used before this script and well work but now i check does not work and i get error

$EmailTo = "something@server.com"
$EmailFrom = "my@gmail.com"
$Subject = "sub" 
$Body = "body" 
$SMTPServer = "smtp.gmail.com" 
$filenameAndPath = "C:\log.txt"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath)
$SMTPMessage.Attachments.Add($attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("user", "pass"); 

I get this error 

Exception calling "Send" with "1" argument(s): "The SMTP server requires a secure connection or the client was not auth
enticated. The server response was: 5.5.1 Authentication Required. Learn more at"

Please advise me 

regards

February 13th, 2015 2:30pm

Set your GMail account to allow less secure apps and retest

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 2:34pm

Sounds like you authentication to the server failed.

Test connection to SMTP server using telnet

February 13th, 2015 2:34pm

Google and PowerShell have issues with TLS.

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 9:08pm

Use port 465 for SSL connections.See: https://www.google.com/#newwindow=1&q=google+smtp+server

Warning: tright now gmail is in a meltdown state.

February 13th, 2015 9:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics