0
votes

I get the error:

Send-MailMessage : 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
At C:\documents\yes.ps1:22 char:1
+ Send-MailMessage @EmailSplat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept ion
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

$MyEmail = "****@gmail.com"
$SMTP= "smtp.gmail.com"
$To = "****@gmail.com"
$Subject = "Attachments"
$Body = "Here's the attachment"
$Creds = (Get-Credential -Credential "$MyEmail")
$env:localappdata

Start-Sleep 2
$Attachments = get-childitem "$env:******" | select-object -ExpandProperty FullName
$EmailSplat = @{To = $to
                From = $MyEmail
                Attachments = $Attachments
                Subject = $Subject
                Body = $Body
                SmtpServer = $SMTP
                Credential = $Creds
                UseSsl = $True
                Port = 587
                DeliveryNotificationOption = 'never'
                }
Send-MailMessage @EmailSplat
2
Try to format the error message: 1) paste 2) a) mark b) use "the “ ”-button" to turn into a block quote 3) Append two blanks to each line that shall be followed by a line break.greybeard
Since you are using gmail, this seems relevant.Mike Zboray

2 Answers

1
votes

You need to enable Allow less secure apps in your google account because Google may block sign in attempts from some apps (or devices) that don't use modern security standards.

Sign into google account, and after that, go to:

https://www.google.com/settings/security/lesssecureapps

And enable the Allow less secure apps option.

Enable less secure apps option

1
votes

The step without which this won't work is : App Password


After Allow less secure apps, I was still facing the same issue because google recently updated its authentication mechanism. Here are the steps

  1. Make Sure the account from which you're trying to send mail has Two Factor Authentication enabled and it has also Allow less secure apps enabled.
  2. If you're successful with step 1, You will be able to see App Passwords options.
  3. Just select the appropriate option where you want to use your google account.

For the OP, My images shows what you need.

After Enabling Two Factor Authentication this is what should be there

After creating app password