none
open outlook from c# with attachment from Bitmap RRS feed

  • Question

  • Hello:

    I have this code :

             

        Outlook.Application objApp = new Outlook.Application();


                Outlook.MailItem mail = null;
                mail = (Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem);
                //The CreateItem method returns an object which has to be typecast to MailItem 
                //before using it.
                mail.Attachments.Add((object)@"C:\Chrysanthemum.jpg",
               Outlook.OlAttachmentType.olEmbeddeditem,
               1, (object)"Attachment");

                //To show email window
                mail.Display();

    it works but I need to change attachment from "C:\Chrysanthemum.jpg" with Image in stream

    I do not want path I need it from stream

    thanks

    • Moved by BonnieBMVP Friday, December 13, 2013 2:27 PM More appropriate forum
    Thursday, December 12, 2013 5:24 PM

Answers

  • You cannot pass anything but a file path or another MailItem object to Attachments.Add in the Outlook Object Model.

    If you want to work directly with the IStream interface (the COM interface, not the .Net one), you will need to use Extended MAPI (C++ or Delphi) or Redemption.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Marvin_Guo Friday, December 20, 2013 9:06 AM
    Friday, December 13, 2013 2:49 PM
  • Hello kme_uk,

    The Outlook Object Model doesn't provide any method for implementing the described scenario.

    As a workaround you can use Extended MAPI functions. It looks like you are interested in the IMAPIProp.OpenProperty method which works with the IStream interface. The System.Runtime.InteropServices.Marshal class can help you with mapping unmanaged types.

    Be aware that Microsoft doesn't recommend using Extended MAPI from a managed. However, I have never seen any issues.

    • Marked as answer by Marvin_Guo Friday, December 20, 2013 9:06 AM
    Friday, December 13, 2013 8:10 PM

All replies