关于Powershell 发送邮件的问题


PowerShell交流中心分类: 进程和服务关于Powershell 发送邮件的问题
0
JMilk Fan asked 8 年 ago

我在Win server 2012中可以使用OutLook发送邮件,但是为什么当我使用Send-MailMessage 指令发邮件的时候就会出先错误,如下OUTPUT(由于公司保密邮件地址以XXX代替,谢谢各位):
PS D:\Users\oe-fanguiju> Send-MailMessage -To XXX@XXX.com -From XXX@XXX.com -Subject “Escort Script E-mail” -Body “$currentTime [EscortTriage.ps1]: Just test” -SmtpServer xxx.xxx.com
Send-MailMessage : Unable to connect to the remote server
At line:1 char:1
+ Send-MailMessage -To fan.guiju@oe.21vianet.com -From fan.guiju@oe.21vianet.com – …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
 
 

1 Answers
1
Best Answer
beanxyz answered 8 年 ago

你是否需要定义端口25? 你看看能否解析或者ping通你的smtp服务器
比如我用的是office365,默认端口是587,那么我使用的是
Send-MailMessage -To $to -From $from -cc $cc -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml -UseSsl -port 587 -Attachments $attach

Mooser Lee 管理员 replied 8 年 ago

同意,这个问题基本上就是端口了。因为Unable to connect to the remote server,除非邮件服务器也是错的。