2010-11-16 93 views
4

我需要嵌入圖像作爲電子郵件的一部分,在用戶簽名之後,而不是在電子郵件的末尾,因爲如果我發送大郵件的回覆,則嵌入的圖像這將是在電子郵件鏈VSTO Outlook嵌入圖像MailItem

  • 的底部我如何嵌入圖像作爲電子郵件內容(不向外部圖像的鏈接)的一部分?
  • 如何在用戶簽名後添加此圖片?

我和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 
     } 
    } 
+0

http://stackoverflow.com/documentation/outlook-addin/commit – 2016-07-28 04:32:48

回答

9

最後我解決了這個問題:

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(); 
    } 

} 
+0

我得到一個ArgumentException,直到我將SetProperties更改爲SetProperty來代替。 – Boog 2011-11-28 17:44:44

+1

如何通過傳遞實際的圖像對象而不是圖像的路徑來實現上述結果? – johnnie 2012-02-06 12:06:37

+1

RTF格式的電子郵件呢?這就是我現在想弄明白的。 – 2013-02-20 18:20:50

相關問題