如何在 Outlook 2007 VSTO 上嵌入图像

发布于 2025-01-02 19:58:05 字数 1691 浏览 0 评论 0原文

大家好,我正在创建一个 Outlook 2007 加载项。我的项目的资源文件夹中有一堆图像,我对资源文件夹内的图片执行 foreach 操作,并为每个项目创建按钮并将按钮背景设置为图像。然后在按钮上单击“我想将按钮的图像添加到电子邮件正文”。我在下面有这个方法,但是我无法将 IMage 对象传递给我需要图像的完整路径的方法。

请指教该怎么办!

if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
                {
                    int mailBodyLength;
                    if (mail.Body == null)
                    {
                        mailBodyLength = 0;
                    }
                    else
                    {
                        mailBodyLength = mail.Body.Length;
                    }
                    //Get Image + Link
                    Image imagePath = image;
                    object linkAddress = "http://www.pentavida.cl";

                    //CONTENT-ID
                    const string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
                    string contentID = Guid.NewGuid().ToString();

                    //Attach image               
                    mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);
                    mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

                    //Create and add banner
                    string banner = string.Format(@"<br/><a href=""{0}"" ><img src=""cid:{1}"" ></a></body>", linkAddress, contentID);
                    mail.HTMLBody = mail.HTMLBody.Replace("</body>", banner);

                    mail.Save();
                }

提前致谢。

Hi guys I am creating an Outlook 2007 add-in. I have a bunch of images in my resources folder of my project, i do a foreach on the pictures inside my resources folder and create buttons foreach item and set the buttons background to the image. Then on the buttons click i want to add the image of the button to the email body. I have this method below, but I cannot pass the IMage object to the method i need the full path of the image.

Please advise on what to do!

if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
                {
                    int mailBodyLength;
                    if (mail.Body == null)
                    {
                        mailBodyLength = 0;
                    }
                    else
                    {
                        mailBodyLength = mail.Body.Length;
                    }
                    //Get Image + Link
                    Image imagePath = image;
                    object linkAddress = "http://www.pentavida.cl";

                    //CONTENT-ID
                    const string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
                    string contentID = Guid.NewGuid().ToString();

                    //Attach image               
                    mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);
                    mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

                    //Create and add banner
                    string banner = string.Format(@"<br/><a href=""{0}"" ><img src=""cid:{1}"" ></a></body>", linkAddress, contentID);
                    mail.HTMLBody = mail.HTMLBody.Replace("</body>", banner);

                    mail.Save();
                }

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪我们做朋友吧 2025-01-09 19:58:05

为什么不将图像保存到临时文件夹,然后在将其附加到邮件对象后立即将其删除:

using System.Reflection;
using System.IO;

//Attach image
object missing = System.Reflection.Missing.Value;

Image car = OutlookAddIn1.Properties.Resources.Car;

string path = Path.Combine(Path.GetTempPath(), "Car.jpg");
car.Save(path);

if (File.Exists(path))
  {
   mail.Attachments.Add(path,Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,missing, missing);
   File.Delete(path);
  }

Why don't you save the image to the temp folder and then delete it immidiately after attaching it to the mail object:

using System.Reflection;
using System.IO;

//Attach image
object missing = System.Reflection.Missing.Value;

Image car = OutlookAddIn1.Properties.Resources.Car;

string path = Path.Combine(Path.GetTempPath(), "Car.jpg");
car.Save(path);

if (File.Exists(path))
  {
   mail.Attachments.Add(path,Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,missing, missing);
   File.Delete(path);
  }
溺ぐ爱和你が 2025-01-09 19:58:05

约翰尼,我相信这只是一个简单的错误。这是我所做的更改。

mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperty(schemaPrAttachContentId, contentId);

Johnnie, I believe it is only a simple error. Here is the change I have made.

mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

to

mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperty(schemaPrAttachContentId, contentId);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文