Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

azure - Send-MailMessage :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP;

I am trying to write a script for automated mail with PowerShell. Below is my script. I don't why I am getting authentication error. I am suspecting that I might need to add certificate. for testing purpose I have self signed certificate on my local machine but I am not sure how to add it in this script. If it's not certificate then please suggest me why i am getting this error and what is the solution.

PS:- I have looked into other stackoverflow answer but none helped.

# Define clear text string for username and password
    [string]$userName = '[email protected]'
    [string]$userPassword = 'xxxx@paxxxword'
    # Convert to SecureString
    [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
    # Get the credential
    [pscredential]$credential = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
    #$credential = Get-Credential
    ## Define the Send-MailMessage parameters
    $mailParams = @{
        SmtpServer                 = 'smtp.outlook.com'
        Port                       = '587' # or '25' if not using TLS
        UseSSL                     = $true ## or not if using non-TLS
        Credential                 = $credential
        From                       = '[email protected]'
        To                         = '[email protected]'
        Subject                    = "testing mail with powershell - $(Get-Date -Format g)"
        Body                       = 'This is a test email using SMTP Client Submission'
        DeliveryNotificationOption = 'OnFailure', 'OnSuccess'
    }
    ## Send the message
    Send-MailMessage @mailParams

Below is the error I am getting:-

Send-MailMessage : The SMTP server requires a secure connection or the client 
was not authenticated. The server response was: 5.7.57 SMTP; Client was not 
authenticated to send anonymous mail during MAIL FROM 
[ZR0P278Cxxxx.xxxP278.PROD.OUTLOOK.COM]
At line:26 char:1
+ Send-MailMessage @mailParams
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:Sm 
   tpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.Send 
   MailMessage
question from:https://stackoverflow.com/questions/65932812/send-mailmessage-the-smtp-server-requires-a-secure-connection-or-the-client-was

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You seem to be passing the From address as Email Address, which is not a proper email address. For Outlook, the From needs to be a real address on the Outlook system.

Further, there can be many reasons for this, I recommend you to check on the insights provided by Lydia Zhou here, as well: https://social.technet.microsoft.com/Forums/en-US/22134794-12bf-4673-b67e-2f45510e34fa/530-5757-smtp-client-was-not-authenticated-to-send-anonymous-mail-during-mail-from?forum=onlineservicesexchange


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...