【发布时间】:2018-10-30 02:29:01
【问题描述】:
我正在尝试使用我在this thread 中找到的答案(指向this URL)在 Send-MailMessage 中发送附件而不先保存到磁盘。
它说要使用:
$attachment = [System.Net.Mail.Attachment]::CreateAttachmentFromString($attachmenttext,"test.txt")
但是当我尝试使用 Send-MailMessage 而不是它显示的复杂方式时,我得到了这个错误:
Send-MailMessage -From "email@email.com" -To "email@email.com" -Subject "Subject" -Body $body -SmtpServer "smtp.server.local" -Port 25 -BodyAsHtml -Attachments $attachment
Send-MailMessage : Could not find file 'C:\Windows\system32\System.Net.Mail.Attachment'.
At line:3 char:1
+ Send-MailMessage -From "email@email.com" -To "email@e ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Send-MailMessage], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage
是否可以继续使用此方法使用 Send-MailMessage?或者有什么不同的方法可以让我在不先保存到磁盘的情况下附加文件,同时仍然使用 send-mailmessage?
【问题讨论】:
-
内存中的项目类型。是字符串还是字节数组>
-
不,您必须使用
System.Net.Mail(MailMessage、SmtpClient、Attachment等)中提供的工具手动构建和发送邮件 -
@ArcSet 一个字符串
标签: powershell scripting attachment