电子邮件中的HTML嵌入式图像未显示
这是我第一次编写Power Shell脚本,我试图将电子邮件报告自动发送给我们的用户.我正在创建Outlook对象并尝试使用它.
This is the first time I am writing power shell scripting, I am trying to automatically send email reports to our users. I am creating outlook object and trying to use it.
$Text --> "<br /><font face='Arial'><b><i>For Full Interactive Viewing <a href=http://www.google.com>Click Here</a></i></b></font><br/>"
$MessageImages --> <br/><img src='C:\MyImages\Volume.png'/><br/><br/><hr><br/><img src='C:\MyImages\Value.png'/><br/><br/><hr><br/><hr>
$FinalText = $Text+$MessageImages
现在,我正在创建Outlook对象并将其发送.
Now, I am creating the outlook object and sending it.
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
$mail.importance = 2
$mail.subject = "Reports - Automated Email from user list "
$mail.HTMLBody = $FinalText
$mail.SentOnBehalfOfName ="*********"
$mail.To = "*******"
$mail.Send()
当我运行此脚本时,$MessageImages
中的所有图像在计算机中的电子邮件中都是可见的,因为这些图像位于上述位置,但是当我将其发送给其他人时,它会显示x标记.我可以理解,它无法找到图像,因此无法显示嵌入的图像.有人可以帮我解决这个问题吗?
When I run this script, All images in $MessageImages
are visible in the email in my computer as the images are present in the location mentioned, but when I send it to someone else, it is showing x mark. I can understand that, it is not able to find the image and so not displaying the embedded image. Can someone help me in solving this?
编辑:与System.Net.Mail.MailMessage
或Send-Mailmessage
无关.这使用的是Outlook对象-New-Object -com Outlook.Application
,因此不能视为重复对象.
Edit : This is not related to System.Net.Mail.MailMessage
or Send-Mailmessage
. This is using Outlook object - New-Object -com Outlook.Application
and so it cannot be considered as duplicate.
如果您需要通过电子邮件发送带有图像的HTML报告,则必须将图像附加到该电子邮件中.请参考以下内容,
If u need to send the HTML report with images in email, u have to attach the images with that email. Refer the below one,
$files = Get-ChildItem C:\MyImages\
Foreach($file in $files)
{
$filename = $file.FullName
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList
$filename.ToString()
$attachment.ContentDisposition.Inline = $True
$attachment.ContentDisposition.DispositionType = "Inline"
$attachment.ContentType.MediaType = "image/jpg"
$attachment.ContentId = $file.ToString()
$emailMessage.Attachments.Add($attachment)
}
$SMTPClient.Send($emailMessage)
$attachment.Dispose();
$emailMessage.Dispose();
在HTML中,将图片来源称为img src ="cid:Volume.png"和img src ='cid:Value.png'
In the HTML mention the image source as img src="cid:Volume.png" and img src='cid:Value.png'
尝试一下即可