我试图发送这样的邮件:
Send-MailMessage -From x -Subject ads.log -To y -SmtpServer smtp.office365.com -port 587 -Attachments $path\output.txt
但是我得到的只是这个回应:
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
有人可以告诉我我想念什么吗?还是有任何权利限制?
显示完整的错误消息:
writeErrorStream: True
Exception: System.Net.Mail.SmtpException: Ke vzdálenému serveru se nelze připojit.
TargetObject: System.Net.Mail.SmtpClient
CategoryInfo: InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, C:\Users\Documents\Powershell_project_1\search.ps1: line 27
PipelineIterationInfo : {0, 1}
错误消息显示“无法连接到远程服务器”
答案 0 :(得分:0)
您不需要某种凭证来通过smtp.office365.com
发送电子邮件吗?
类似这样的东西:
$username="alone@home.com"
$password=ConvertTo-SecureString "XXXXX"-AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ($username, $password)
Send-MailMessage -To peterparker76@marvel.com -subject "Send from powerhell" -body "test from powerhell" -UseSsl -Port 587 -SmtpServer smtp.office365.com -From $username -Credential $mycredentials
如果您需要有关错误消息的更多信息,可以随时尝试$error[0] | format-list -force
。