gavin newsom
gavin newsom

Reputation: 11

Why do we get an error? Error sending email: The SMTP server required a secure connection, or the client was not authenticated

try {
    $credentials = new-object Management.Automation.PSCredential “[email protected]”, (“dasfkjaehj5” | ConvertTo-SecureString -AsPlainText -Force) 
    $mailParams  = @{
            'To'          = "[email protected]"
            'From'        = "[email protected]"
            'Encoding'    = 'UTF8'
            'Subject'     = "340."
            'Body'        = "Сообщение отправлено автоматически"
            'Smtpserver'  = "mail.foc.ru"
            'Port'        = 25
            'Attachments' = "E:\FTP\EMEX\price_forceauto.csv"
            'Credential'  = $credentials 
    
    }
  
    Send-MailMessage @mailParams -ErrorAction Stop
}
catch {
    $errorMessage = "Error sending email: $($_.Exception.Message)"
    Write-Warning $errorMessage
    Add-Content -Path 'E:\FTP\EMEX\error.txt' -Value $errorMessage
} 

We recieve an error:

Error sending email: The SMTP server required a secure connection, or the client was not authenticated. Server Response: 5.7.1 Local mailbox [email protected] not found.**

Upvotes: 0

Views: 122

Answers (1)

postanote
postanote

Reputation: 16076

FYI...

SSL sites, now require you to also do this in your code.

# Required for use with web SSL sites
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

Upvotes: 1

Related Questions