Email alerts not working in Azure automation using powershell script

Copper Contributor

Hi All,

Can someone help. I am working on creating a failure alert for my runbooks in Azure automation account using powershell. I am using Send-MailMessage  command to send email when I catch an error in my runbook and then send email to my work email id.

I have created 2 runbooks(powershell) - 1 parent runbook and 1 child runbook and I am checking for parent runbook failure(using try, catch block) to check for any failures. In case of failure in parent runbook, I am calling child runbook(powershell) to send email to my work email id.

When I am testing my child runbook, then it is able to send test email to my work email id but when I am calling the child runbook from parent runbook, then I am facing error: the remote name could not be resolved {SMTP server name}.

Another test I have done is that parent runbook is able to send parameters to child runbook and child runbook is able to display/use those parameter values.

 

Command used in child runbook

Send-MailMessage -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -SmtpServer $smtpServer -Credential $Creds -UseSsl -Port $MailSMTPPort

 

Can anyone advise me what is the problem here?

1 Reply
I wonder if it can't find the server name as it is not running internally - ie on a Hybrid Worker, so it can't resolve the server.

You may be better off leveraging SendGrid to send the emails instead - https://docs.microsoft.com/en-us/azure/automation/automation-send-email