【发布时间】:2019-08-16 21:34:04
【问题描述】:
我正在尝试将图像嵌入到要通过 Powershell 发送的电子邮件中。
下面是我的代码:
$Attachment = New-Object Net.Mail.Attachment($LocalLocation)
$Attachment.ContentDisposition.Inline = $True
$Attachment.ContentDisposition.DispositionType = "Inline"
$Attachment.ContentType.MediaType = "image/png"
$MailMessage = New-Object Net.Mail.MailMessage
$MailMessage.To.Add($emailTo)
$MailMessage.From = $MyEmail
$MailMessage.Subject = "Test Email"
$MailMessage.IsBodyHtml = $True
$MailMessage.Attachments.Add($Attachment)
$MailMessage.Body = "
<html>
<head></head>
<body>
<img src='CID:$($Attachment.ContentId)' />
</body>
</html>"
$SmtpClient = New-Object Net.Mail.SmtpClient("123.0.0.1",25 )
$SmtpClient.Send($MailMessage)
我收到一封电子邮件,但邮件中只有一个空框。 $LocalLocation 是指向我的图像的链接。
我正在使用 Powershell 3
【问题讨论】:
-
在正文中您引用
$Attachment.ContentId但我没有看到您正在为其分配值。
标签: email powershell powershell-3.0