none
Add embedded attachment with project resources. RRS feed

  • Question

  • Hello

    I want to do something like :

    ((MailItem)_inspector).Attachments.Add(
                            Projet.Properties.Resources.MyImage,
                            Outlook.OlAttachmentType.olEmbeddeditem,
                            0,
                            "img"
                            );

    I use Office Add-In 2010 (but must usable on 2007 and 2013). And .Net framwork 4.0. In c# obviously.

    I Have find :

    DirectoryInfo tmpDir = Directory.CreateDirectory(Path.GetTempPath() + "/ezfzf");
    string imgPath = tmpDir.FullName + "AddInIMG3.png";
    FileStream st = new FileStream(tmpDir.FullName + "AddInIMG3.png"FileMode.OpenOrCreate);
    mail.Attachments.Add(imgPath, Outlook.OlAttachmentType.olEmbeddeditem, 0"img");

    I whish find other way more whithout temps file.

    Friday, February 27, 2015 1:32 PM

Answers

  • Hello,

    The Outlook object model doesn't allow to use a stream as a source. The source can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment.

    • Marked as answer by Aurelien312 Friday, February 27, 2015 3:20 PM
    Friday, February 27, 2015 1:36 PM

All replies

  • Hello,

    The Outlook object model doesn't allow to use a stream as a source. The source can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment.

    • Marked as answer by Aurelien312 Friday, February 27, 2015 3:20 PM
    Friday, February 27, 2015 1:36 PM
  • You can do that on the Extended MAPI level only (C++ or Delphi) by opening the PR_ATTACH_DATA_BIN property as IStream and writing to it.

    If using Redemption is an option, it lets you pass IStream COM interface to the RDOMail.Attachments.Add call (you will then need to set the file name property).


    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 Aurelien312 Friday, February 27, 2015 3:25 PM
    • Unmarked as answer by Aurelien312 Friday, February 27, 2015 3:25 PM
    Friday, February 27, 2015 1:59 PM