2010-11-16 6 views
4

Je dois incorporer une image dans le courrier électronique, après la signature de l'utilisateur, et non à la fin de l'e-mail, car si j'envoie une réponse d'un email important, l'image intégrée il va être en bas de la chaîne des e-mailsVSTO Outlook Intégrer l'image MailItem

  • Comment puis-je intégrer une image dans le cadre du contenu e-mail (Pas de lien vers une image)?
  • Comment ajouter cette image après la signature de l'utilisateur?

Je suis le travail avec VSTO, VS2008 Fwk3.5 et Outlook 2007

Voici mon 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 
     } 
    } 
+0

http://stackoverflow.com/documentation/outlook-addin/commit –

Répondre

9

Enfin je l'ai résolu le problème avec ceci:

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

Je recevais une ArgumentException jusqu'à ce que j'ai modifié SetProperties à SetProperty au lieu. – Boog

+1

Comment pouvez-vous obtenir le résultat ci-dessus en passant l'objet image réel et non le chemin de l'image? – johnnie

+1

Qu'en est-il des messages au format RTF? C'est ce que j'essaie de comprendre en ce moment. –

Questions connexes