Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

c# - VSTO Outlook Embed Image MailItem

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
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:\MediaImagenes100MSDCFDSC00632.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();
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...