none
Create Mail Item from RESTful Service Feed RRS feed

  • Question

  • So I am trying to get messages from a RESTful Service that has a From, Body, Creation Date (no subject) and place these messages into a folder in Outlook.  When I try to programmatically create an olMailItem I can't set who the message is From.  Is there a way around this or another way to create message items for a folder?  Basically what I am looking to do is create an Outlook Add-In that checks a RESTful service regularly for messages and pushes them into a folder and leverages all of the benefits of Outlook (e.g. growler messages, etc.)  Is this even possible?   

    Jeff L

    Friday, March 7, 2014 3:30 AM

All replies

  • Hello Jeff,

    What code do you use for setting the From property?

    Note, the Outlook object model doesn't provide such property for their items. Instead, you need to use the Sender property which represents an AddressEntry object that corresponds to the user of the account from which the MailItem is sent. Most sender related properties are read-only: SenderEmailAddress, SenderEmailType and etc.

    > Is this even possible?  

    Yep. Be aware that Office applications use Single Threaded Apartments. So, you shouldn't use the Outlook object model from another threads. You need to work with Outlook objects only on the main thread or use a low-level code from another threads for creating Outlook items: Extended MAPI or any other third-party wrappers around ExMAPI such as Redemption.


    Friday, March 7, 2014 9:03 AM
  • Hi Eugene,

    I hadn't gotten to the code for hydrating the From property as I couldn't seem to be able to pass data to it from the REST service because there was no setter available.  Basically as I get a list of posts from the REST service (e.g. PostedBy, PostedDate, PostedTo, PostedMessage) I would like to take those items and push them into a folder just as you would see in the Inbox.  Right now I have

    Outlook.MailItem mailItem = (Outlook.MailItem)Application.CreateItem(Outlook.OlItemType.olMailItem);
    

     then I hydrate mailItem.Subject = postedTo, mailItem.HTMLBody = postedMessage, etc.  I just can't seem to set From (postedBy) or CreationTime (postedDate). I do use STA to call the method in C#.  This is basically an Outlook 2013 Add-In from VS13 (C#).  Would I have to switch to C++ to get this done?

    Thanks again for your help/guidance.


    Jeff L

    Friday, March 7, 2014 4:01 PM
  • If this code is running in an Outlook addin it's running in the same thread and process space as Outlook. So you shouldn't start any new threads, STA or not, that use the Outlook object model.

    You also cannot set properties such as From or Sender* using the Outlook object model, they are read-only to the object model. You can use Extended MAPI (C++ or Delphi) code or Redemption code (www.dimastr.com/redemption) to set those properties.


    Ken Slovak MVP - Outlook

    Friday, March 7, 2014 4:09 PM
    Moderator
  • Thanks Ken, would you happen to have a URL that provides guidance to do this with C++ and Extended MAPI based on the requirements mentioned above?

    I appreciate it.


    Jeff L

    Friday, March 7, 2014 4:38 PM
  • Not for Extended MAPI/C++ , no.

    With Redemption you can create a new mail item (RDOMail) and set the Sender property to an AddressEntry object and that will set the sender* properties such as From. There should be various examples using Redemption code on the Web site (www.dimastr.com/redemption).


    Ken Slovak MVP - Outlook

    Friday, March 7, 2014 4:52 PM
    Moderator
  • Hi Jeff,

    Please see the MAPI Programming Overview section in MSDN.

    Friday, March 7, 2014 4:53 PM
  • Being that these are readonly items (posts) that will go into a local store (PST) and are for reading only or clicking on a link in the message (no reply or that sort) should I just create a custom form and hydrate that form with the information bypassing the Mail/Post Item all together?  All this local store is doing is pulling posts from the REST service and placing the posts into folders broken down by the PostedTo field.

    Jeff L

    Friday, March 7, 2014 5:12 PM
  • Thanks Eugene, I am thinking that I may need to rethink this as it really isn't an "Emailing" function.  This is not really going to an SMTP based server.  This is checking a REST service for posts and hydrating a local store with these posts.  They aren't really receive/reply email messages.  At the most we may need to send a REST call back if they want to comment on the post, like the post, etc.  This will never send an email, not receive an email.

    Jeff L

    Friday, March 7, 2014 5:16 PM
  • A custom form is based on a standard form such as email (IPM.Note) or post (IPM.Post), so I don't really see an advantage in a custom item unless you want to display properties that don't normally show up in an email or post item. No matter what you'd still be hydrating an Outlook item if you want it displayed in Outlook folders in an Outlook store.

    Ken Slovak MVP - Outlook

    Friday, March 7, 2014 5:37 PM
    Moderator