So what am I doing wrong here? I want a script to send an email to my Gmail
account (the script will run as a scheduled task). But it keeps failing
with:

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

Even tho I am using SSl, and passing it credentials to authenticate. I
don't really want to set my GMail account to accept less secure apps, but
what am I doing wrong here?
(I have my own Google Apps account, so I use my own domain name)

$EmailFrom = "Scheduled Tasks <[email protected]>"
$EmailTo = "me@my-domain"
$EmailSubject = "Results of scheduled tasks"
$EmailBody = "Attached is the Log"

$EmailSMTPServer = "smtp.gmail.com"
$EmailSMTPServerPort = "587"

$EmailSMTPUser = "me@my-domain"
$EmailSMTPPass = "xxxxx"

$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$
EmailSubject,$EmailBody)

$SMTP = New-Object System.Net.Mail.SmtpClient($EmailSMTPServer,
$EmailSMTPServerPort);
$SMTP.EnableSSL = $true
$SMTP.Credentials = New-Object System.Net.NetworkCredential($EmailSMTPUser,
$EmailSMTPPass);
$SMTP.Send($SMTPMessage);

So why does it think it either doesn't have a secure connection (I am using
EnableSsl) or not authenticating (I am passing it my Google Apps ID and
password)?

Running on Win 10, PS v5

PS C:\Scripts> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.1.14393.206
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.206
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Thanks

Reply via email to