VSTO Outlook 嵌入图像邮件项目

发布于 2024-10-02 13:47:22 字数 807 浏览 0 评论 0原文

我需要在用户签名之后嵌入图像作为电子邮件的一部分,而不是在电子邮件末尾,因为如果我发送一封大电子邮件的回复,嵌入的图像将位于电子邮件的底部电子邮件链

  • 如何嵌入图像作为电子邮件内容的一部分(不是外部图像的链接)?
  • 如何在用户签名后添加此图像?

我正在使用 VSTO、VS2008 Fwk3.5 和 Outlook 2007

以下是我的代码:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
    }

    private void Application_ItemSend(object Item, ref bool Cancel)
    {
        if (Item is Outlook.MailItem)
        {
            Outlook.MailItem mailMessage = (Outlook.MailItem)Item;
            //do something to add the image after the signature
        }
    }

I need to embed an image as a part of the email, after the User Signature, not at the end of the email, becasue if i'm sending a reply of a large email, the embedded Image it's going to be at the bottom of the emails chain

  • How do I embed an image as part of the email content (Not a link to an outside image)?
  • How do I add this image after the user Signature?

I'm work with VSTO, VS2008 Fwk3.5 and Outlook 2007

Here is my code:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
    }

    private void Application_ItemSend(object Item, ref bool Cancel)
    {
        if (Item is Outlook.MailItem)
        {
            Outlook.MailItem mailMessage = (Outlook.MailItem)Item;
            //do something to add the image after the signature
        }
    }

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

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

发布评论

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

评论(1

禾厶谷欠 2024-10-09 13:47:22

最后我解决了这个问题:

private void SendFormatted(Outlook.MailItem mail)
{
    if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
    {
        //Get Image + Link
        string imagePath = @"D:\\Media\Imagenes\100MSDCF\DSC00632.JPG";
        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, Outlook.OlAttachmentType.olByValue, mail.Body.Length, 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();
    }

}

Finally i Solved the problem with this:

private void SendFormatted(Outlook.MailItem mail)
{
    if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
    {
        //Get Image + Link
        string imagePath = @"D:\\Media\Imagenes\100MSDCF\DSC00632.JPG";
        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, Outlook.OlAttachmentType.olByValue, mail.Body.Length, 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();
    }

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