简体   繁体   English

带有附件的PowerShell 5.0 Send-MailMessage

[英]PowerShell 5.0 Send-MailMessage with Attachment

The following command successfully sends an e-mail using the parameters specified in the command:- 以下命令使用命令中指定的参数成功发送电子邮件:

Send-MailMessage -From "<mailbox@domain.com>" -To "<mailbox@domain.com>" -Subject "Sending the Attachment" -Body "Forgot to send the attachment. Sending now." -SmtpServer "fqdn.smtprelay.com"

As soon as I add any kind of attachment, regardless of size, file extension (.txt, .zip etc.) the command apparently completes without generating any kind of error into the console output but the e-mail never hits the SMTP relay when I track the mail, it's almost as if the command fails but according to PowerShell it hasn't, it executes the command without any kind of output. 一旦添加任何类型的附件,无论大小,文件扩展名(.txt,.zip等)如何,该命令显然都会完成,而不会在控制台输出中产生任何类型的错误,但是当出现以下情况时,电子邮件永远不会触发SMTP中继我跟踪邮件,几乎就像命令失败一样,但是根据PowerShell却没有,它执行命令时没有任何输出。

This is the command I'm using: 这是我正在使用的命令:

Send-MailMessage -From "<mailbox@domain.com>" -To "<mailbox@domain.com>" -Subject "Sending the Attachment" -Body "Forgot to send the attachment. Sending now." -SmtpServer "fqdn.smtprelay.com" -Attachments "C:\Temp\targetfile.zip"

Does any body have any advice on how I can go about troubleshooting further? 有人对我如何进一步进行故障排除有任何建议吗? It seems to be such a simple issue but I feel that I have now exhausted all options. 这似乎是一个简单的问题,但是我觉得我已经穷尽了所有选择。 I have verified that the target file exists and can be accessed from the PowerShell console. 我已验证目标文件存在并且可以从PowerShell控制台访问。

Also, I can successfully establish a telnet connection to the SMTP relay on port 25 without authentication and generate a basic e-mail, the problem seems to be when I add an attachment. 另外,我可以在不进行身份验证的情况下在端口25上成功建立到SMTP中继的telnet连接,并生成基本的电子邮件,问题似乎出在添加附件时。

New hosted e-mail security system was rejecting mail based on security policies, because the attachment was an unzipped HTML file attached to the e-mail it was being rejected as a potential security threat. 新的托管电子邮件安全系统正在基于安全策略拒绝邮件,因为附件是附加到电子邮件的未压缩HTML文件,它被拒绝为潜在的安全威胁。

Added new code to firstly compress file before attaching to e-mail and sending - now works perfectly. 添加了新代码,可以在附加到电子邮件和发送之前首先压缩文件-现在可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM