none
How to embed inline image and send an email ? RRS feed

  • Question

  • How to embed inline image into the mail body and send an email using exchange server.
    Tuesday, January 25, 2011 11:57 AM

Answers

  • When you add the attachment (using CreateAttachment) you will need to set the ContentId property to a known value.  This can be anything you like, as long as it is unique within the message.  If you like, you can set it to the filename.  If you had set it to "screenshot.jpg", then your <img src="cid:screenshot.jpg"/> would have worked.

    http://msdn.microsoft.com/en-us/library/aa580492(EXCHG.140).aspx


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    • Marked as answer by Venkatesh Basi Thursday, February 3, 2011 3:28 AM
    Wednesday, February 2, 2011 1:45 PM

All replies

  • I've never tried it, but I have had to write code that reads inline images, so I think I can make a guess.  You would need to add the image as an attachment, and set the ContentId property to some known arbitrary value, like (for example) Image001.  Then, where you want the image to appear in the message body, you add an <img> tag like this:

    <img src="cid:Image001">


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Tuesday, January 25, 2011 3:21 PM
  • Basi,

     

    Try this http://www.systemnetmail.com/faq/4.4.aspx

    Tuesday, January 25, 2011 8:12 PM
  • The above two apporaches are fine using System.Net.Mail. But I want to approach similar using exchange server. Please let me know the ideas.
    Thursday, January 27, 2011 5:23 AM
  • Please let me know if I am not clear.
    Friday, January 28, 2011 8:30 AM
  • What Exchange programming experience do you have?  The approach I described above should work with Exchange.
    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Friday, January 28, 2011 2:13 PM
  • 1. I am successfully creating item request using the below code.

     CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);

    2. After executing this line I could see the createItemResponse.ResponseMessages.Items[0].ResponseClass as Success.

     ItemInfoResponseMessageType responseMessage =
    createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;

    But to attach any thing, we need to specify the ParentItemId for CreateAttachmentType() instance. The parentItemId has to be responseMessage.Items.Items[0].ItemId.Id.ToString().

    But I am getting null for responseMessage.Items.

     

    Please let me know where I am doing wrong.

    Monday, January 31, 2011 4:34 AM
  • If you open the mailbox in Outlook, do you see the item actually being created?

    There is some example code which I think describes what you are trying to do about halfway down this page:

    http://www.codeproject.com/KB/exchange/Exchange2007EWS-Part1.aspx

     


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Monday, January 31, 2011 2:40 PM
  • Yes, the item is created but without attachment.

     

    I have checked this website already. I am trying to pass parentItemId for creating attachment. But I am getting the createItem reasponse for responseMessage.Items is null. If I get ItemId from responseMessage.Items.Items[0].Item. Then I could pass as parentItemId for createAttachmentType() instance.

     

     

    Tuesday, February 1, 2011 5:17 AM
  • Yes, the item is created but without attachment.

     

    I have checked this website already. I am trying to pass parentItemId for creating attachment. But I am getting the createItem reasponse for responseMessage.Items is null. If I get ItemId from responseMessage.Items.Items[0].Item. Then I could pass as parentItemId for createAttachmentType() instance.

     

     

    Tuesday, February 1, 2011 9:31 AM
  • Please let me know if you need any further information.
    Tuesday, February 1, 2011 10:53 AM
  • It could be that Exchange is not ready to return the ItemId to you at the time you ask for it as described in the article linked below.  I would also make sure that you are setting the MessageDisposition to SaveOnly, to make sure that the item stays in the Drafts folder.  I don't know what you are setting to, but if it is SendAndSaveCopy (and if you are not setting it, I don't know what will be the default value), it stands a good chance of being moved as soon as it gets created.

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/9b32fb91-32a7-4f97-aafb-a3f8bc97a303


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Tuesday, February 1, 2011 1:29 PM
  • Yes, previously I was using SendAndSaveCopy, using this I am getting null for returned ItemId. Now I just tried with SaveOnly then I am getting a value for itemId returned.

    Now I have used this id for attachement parentid and successfully created an email with attachemnt. But i just tried to use attachment as inline of messagebody as below.

    <html><body><img src='cid:screenshot.jpg'/></body></html>

    But the image is not appearing as inline messagebody, it is still showing as attachment for the message.

     

    Please guide me how to embed the attached image into message body.

    Wednesday, February 2, 2011 5:22 AM
  • Please let me know if you need any further information.
    Wednesday, February 2, 2011 9:07 AM
  • When you add the attachment (using CreateAttachment) you will need to set the ContentId property to a known value.  This can be anything you like, as long as it is unique within the message.  If you like, you can set it to the filename.  If you had set it to "screenshot.jpg", then your <img src="cid:screenshot.jpg"/> would have worked.

    http://msdn.microsoft.com/en-us/library/aa580492(EXCHG.140).aspx


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    • Marked as answer by Venkatesh Basi Thursday, February 3, 2011 3:28 AM
    Wednesday, February 2, 2011 1:45 PM
  • Thank you so much Lee, it did work.
    Thursday, February 3, 2011 3:28 AM