· 6 years ago · Jun 15, 2019, 12:00 AM
1$From = Read-Host "Enter your gmail address"
2$UserName = Read-Host "Enter your gmail username (address without @gmail.com)"
3$UserPass = Read-Host "Enter your Gmail Password (will not be stored)" -AsSecureString
4$SecurePassword = $UserPass| ConvertTo-SecureString -AsPlainText -Force;
5$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword;
6 $To = Read-Host "Who are you sending this to?"
7 $Subject = Read-Host "Subject"
8 $Body = Read-Host "Message"
9 $SMTPServer = "smtp.gmail.com"
10 $SMTPPort = "587"
11Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credential
12
13Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was:
145.5.1 Authentication Required. Learn more at
15At C:UsersServerSERVERAppdatasendemail.ps1:11 char:1
16+ Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -S ...
17+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
19 + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage