Am I the only person on this sub who has tried to pass Gmail credentials through a scheduled script?

Looking to schedule some automated emails via Task Scheduler using Gmail (or Office 365 if needed).

Either my Google-Fu is failing me or its much harder than it seems:

$emailSubject = “xxx – Windows Server Backup on $env:computername Completed Successfully” $emailBody = “xxx – The Windows Server Backup job on $env:computername completed successfully!” $username = “xxxx@gmail.com
$pwd = “xxx”
$securepwd = ConvertTo-SecureString $pwd -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securepwd

Send-MailMessage -SmtpServer smtp.gmail.com -Credential $credentials -From xxxxxx@gmail.com -To xxxx@domain.com -Subject $emailSubject -Body $emailBody -UseSSL

Error I’m mostly getting while experimenting:

Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

Any ideas?

submitted by /u/TapTapLift
[link] [comments]

Leave a Reply