0

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
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    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 Apr 28 '18 at 17:45
  • Since you are using gmail, [this](https://stackoverflow.com/a/25215834/517852) seems relevant. – Mike Zboray Apr 28 '18 at 19:35

2 Answers2

2

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

Victor Silva
  • 723
  • 4
  • 17
1

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

Jeet patel
  • 11
  • 1