问题
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
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()
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?
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.
回答1:
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();
In the HTML mention the image source as img src="cid:Volume.png" and img src='cid:Value.png'
Try it'll works
来源:https://stackoverflow.com/questions/32469812/html-embedded-image-in-the-email-not-displayed