You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Send-MailMessage在PowerShell控制台、VS Code可用,Azure Runbook却失效?

Azure PowerShell Runbook发送邮件连接失败排查方案

使用以下Send-MailMessage脚本在Azure PowerShell Runbook中发送邮件时:

Send-mailmessage -from "noreply@company.com" -to "me@company.com" -subject "test" -smtpserver "smtp_server"

出现连接超时错误:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

可从以下几点排查:

  • 检查SMTP端口与加密方式:
    Azure Runbook环境默认封禁25端口,需改用587(TLS)或465(SSL)端口,同时添加-UseSsl参数启用加密。若服务器需要身份验证,需搭配-Credential参数传入存储在Azure自动化的凭据:

    $smtpCred = Get-AutomationPSCredential "SmtpAccountCredential"
    Send-MailMessage -From "noreply@company.com" -To "me@company.com" -Subject "test" -SmtpServer "smtp_server" -Port 587 -UseSsl -Credential $smtpCred
    
  • 验证SMTP服务器的网络可达性:
    确认SMTP服务器允许公网访问,或已将Azure自动化账户的出站IP地址加入服务器白名单。可在Runbook中先测试连通性:

    Test-NetConnection -ComputerName "smtp_server" -Port 587
    
  • 检查Azure自动化网络配置:
    若自动化账户使用了专用终结点或虚拟网络集成,需确保虚拟网络的出站规则允许访问目标SMTP服务器的端口。

  • 确认SMTP服务器状态:
    排查SMTP服务器本身是否正常运行,未出现宕机、过载或IP封禁等情况。

内容的提问来源于stack exchange,提问作者Mukesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 18:13:11