未显示电子邮件中的HTML嵌入图像

未显示电子邮件中的HTML嵌入图像,html,powershell,outlook,html-email,Html,Powershell,Outlook,Html Email,这是我第一次编写powershell脚本,我尝试自动向用户发送电子邮件报告。我正在创建outlook对象并尝试使用它 $Text --> "<br /><font face='Arial'><b><i>For Full Interactive Viewing <a href=http://www.google.com>Click Here</a></i></b></font><

这是我第一次编写powershell脚本,我尝试自动向用户发送电子邮件报告。我正在创建outlook对象并尝试使用它

$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
当我运行此脚本时,$MessageImages中的所有图像在我的计算机中的电子邮件中都可见,因为这些图像出现在提到的位置,但当我将其发送给其他人时,它会显示x标记。我可以理解,它无法找到图像,因此无法显示嵌入的图像。有人能帮我解决这个问题吗


编辑:这与System.Net.Mail.MailMessage或Send MailMessage无关。这是使用Outlook对象-新建对象-com Outlook.Application,因此不能将其视为重复

如果您需要在电子邮件中发送包含图像的HTML报告,您必须将图像附加到该电子邮件中。参考下面的一个

$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'


试试看,它会起作用的

可能是重复的。在这个问题上,有一个链接指向另一个副本。看看这两个问题,看看你是否能找到答案。到目前为止,您的问题是您正在html中使用本地路径。您需要使用相对路径并将图像作为附件附加。这与System.Net.Mail.MailMessage或Send MailMessage无关,但我在此处使用Outlook对象。您是否尝试使用新对象-com Outlook.Application?
$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();