Send-MailMessage -SmtpServer "smtp.com.au" -From "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0ada580ada5eea3afad" rel="noreferrer noopener nofollow">[email protected]</a>" -To "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e17011b2e17011b400d0103" rel="noreferrer noopener nofollow">[email protected]</a>" -Subject "Testing" -Attachments "\\Test\archive.zip" -Body "attached"
我正在使用上述命令通过电子邮件发送 zip 文件,但我在“收件人”( [email protected] ) 邮箱中没有看到任何内容。
命令成功运行,没有任何错误。
最佳答案
我认为问题出在你的函数调用上。你错过了很多参数。看看我的 Gmail 示例:
$password = ConvertTo-SecureString "123456789" -AsPlainText -Force
$emailCredentials = New-Object pscredential ("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375145585a77505a565e5b1954585a" rel="noreferrer noopener nofollow">[email protected]</a>", $password)
try {
Send-MailMessage -From "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0462766b69446369656d682a676b69" rel="noreferrer noopener nofollow">[email protected]</a>" -To "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681c07281c07460b0705" rel="noreferrer noopener nofollow">[email protected]</a>" -Subject "subject" -Body "body" -SmtpServer "smtp.gmail.com" -Port 587 -Credential $emailCredentials -Encoding UTF8 -UseSsl -ErrorAction Stop
}
catch {
echo $error[0]
}
您的调用中没有 -Credential
参数,我几乎可以肯定,这就是问题所在。另外,您的 smtp 服务器可能在不同端口上有此协议(protocol),这就是 -Port
的用途。最后-UseSsl
,如果smtp服务器正在加密邮件,那么如果没有这个开关,您的电子邮件将不会发送。 -编码 UTF8
仅适用于区域字符。
检查您的$error[0]
,它可能会告诉您问题出在哪里。检查您的 -From
电子邮件发生了什么情况。在 Gmail 上,您有时会看到自动重新编译,并带有错误描述。
很抱歉没有为您提供简单的解决方案,但我没有足够的信息来找到它。
关于powershell - 未收到使用 powershell 命令发送的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200232/