How to send email from Azure automation runbook

T Crha 396 Reputation points
2023-05-04T12:07:26.8333333+00:00

Hello,

I am trying to create a runbook in Azure Automation account, that should collect some data and in the end send them via email.

But when I define the "mail send section" like this:


$emailParams = @{
    From       = "******@domain.com"
    To         = "******@domain.com"
    Subject    = "Test Email"
    Body       = 'report'
    SmtpServer = "smtp.office365.com"
    Port       = 587
    Credential = $credential
    UseSsl     = $true
}

Send-MailMessage @emailParams

($credential variable contains Automation account stored credential with Global reader rights, referenced via


$Credential = Get-AutomationPSCredential -Name "Cred name"

I get following error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.3 Authentication unsuccessful

Account that I stored within AA credentials has valid password, I can login to portal.office.com under that identity.
What is wrong? How can I send an email from AZ runbook? What is my stored credential missing?

Many thanks,

Tomas

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. SwathiDhanwada-MSFT 18,996 Reputation points Moderator
    2023-05-10T04:36:59.98+00:00

    @T Crha Thanks for your query. Kindly note that the Send-MailMessage cmdlet is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell for sending email using SMTP server, we recommend you do not use Send-MailMessage.

    You can try using Microsoft Graph commands to send the email from automation account. Here are some reference documents to get you started with


2 additional answers

Sort by: Most helpful
  1. Limitless Technology 44,751 Reputation points
    2023-05-05T16:10:38.59+00:00

    Hello

    Thank you for your question and reaching out.

    I would like to invite you to have a look on below reference URL mentioning prerequires and step by step instructions.

    https://learn.microsoft.com/en-us/azure/automation/automation-send-email

    --If the reply is helpful, please Upvote and Accept as answer--


  2. Rogostan Kazinsky 0 Reputation points
    2023-09-11T09:57:34.0233333+00:00

    No, you don't need a 3rd party when this is possible to do via Graph Send.Mail and using Send-MgUserMail

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.