使用Powershell中的Outlook对象将图像嵌入到电子邮件中

编程入门 行业动态 更新时间:2024-10-27 08:23:46
本文介绍了使用Powershell中的Outlook对象将图像嵌入到电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经发布了与此相关的问题(电子邮件未显示),并更新了我的脚本以包含cid,但是现在我的图像已附加,而不是内嵌.我不确定如何在Outlook对象中使用嵌入式图像.

I already posted a question related to this (HTML embedded image in the email not displayed ) and updated my script to include cid, but now my images are attached rather than coming inline. I am not sure how I can use inline images in outlook object.

$Text --> "<br /><font face='Arial'><b><i>For Full Interactive Viewing <a href=www.google>Click Here</a></i></b></font><br/>" $MessageImages --> <br/><img src='cid:Volume.png'/><br/><br/><hr><br/><img src='C:\MyImages\Value.png'/><br/><br/><hr><br/><hr> $FinalText = $Text+$MessageImages

然后我要创建一个Outlook对象并将其与附件一起发送.

Then I am creating an outlook object and sending it with attachments in 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.Attachments.Add($file.ToString()) $mail.Send()

它已附加,没有任何问题,但未嵌入嵌入式.任何人都可以帮忙.

It is attached without any issue, but not embedded inline. Can anyone help on this.

我没有smtp服务器详细信息,所以我不能使用smtp客户端.因此,我尝试如下使用此类System.Net.Mail.Attachment,但是当我尝试如下添加附件时,

I dont have smtp server details and so I cannot use smtp client. So I tried to use this class System.Net.Mail.Attachment as below, but when I tried to add the attachment as below,

PS H:\> $file Directory: C:\Users\Images Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 23/09/2015 4:04 p.m. 132361 Volume.png $attachment = New-Object System.Net.Mail.Attachment –ArgumentList ($file.FullName).ToString() $attachment.ContentDisposition.Inline = $True $attachment.ContentDisposition.DispositionType = "Inline" $attachment.ContentType.MediaType = "image/png" $attachment.ContentId = $file.Name.ToString() $mail.Attachments.Add($attachment)

我收到此错误-

Exception calling "Add" with "1" argument(s): "Value does not fall within the expected range." At C:\work\Automated.ps1:130 char:23 + $mail.Attachments.Add <<<< ($attachment) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation

有人可以协助我如何在Outlook对象中使用嵌入式图像吗?

Can someone assist me on how to use inline images in outlook object.?

推荐答案

您需要将PR_ATTACH_CONTENT_ID属性设置为cid属性(在您的情况下为Volume.png)的匹配值:

You will need to set the PR_ATTACH_CONTENT_ID property to the matching value of the cid attribute (Volume.png in your case):

$attach = $mail.Attachments.Add($attachment) $attach.PropertyAccessor.SetProperty("schemas.microsoft/mapi/proptag/0x3712001F", "Volume.png")

更多推荐

使用Powershell中的Outlook对象将图像嵌入到电子邮件中

本文发布于:2023-11-09 03:09:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   电子邮件   对象   Powershell   Outlook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!