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
“ ”
-button" to turn into a block quote 3) Append two blanks to each line that shall be followed by a line break. – greybeard