title: Get sent message in Outlook Addin
body: <p>I am facing some problems trying to get the sent message from an Outlook plugin.</p>
  
  <p>In <em>onItemSend</em> event, I open a dialog where it shows some fields, with message information such as recipients, subject, etc and a button that will save these information into our DB. Another requirement is to save a copy of the sent message and this is where I got stuck...</p>
  
  <p>I could save the message using the <em>SaveAs</em> method but the problem is when I open the message, it shows: </p>
  
  <blockquote>
    <p><strong>This message has not been sent. This message will be sent via</strong>
    <strong>Microsoft Exchange</strong></p>
  </blockquote>
  
  <p>causing some problems with users, making them think that the message was not sent.</p>
  
  <p>During my searches, I found <a href="http://social.msdn.microsoft.com/forums/office/en-US/1ace559a-16cb-4282-b55a-4cb52fbffabe/outlook-2007-this-message-has-not-been-sent" rel="nofollow">this thread</a> where another person had the same problem and the solution was to use the message as PostItem instead of MailItem, once the PostItem is created in sent state. Also, we should set the MessageClass property to <em>IPM.Note</em> and delete PR_ICON_INDEX</p>
  
  <p>Here is the code that I am using to do the steps above. I found this code <a href="http://social.msdn.microsoft.com/Forums/office/en-US/7242c3e7-66e7-44f7-9ec0-595e9f9000a1/how-to-set-msgflagunsent-via-c?forum=outlookdev" rel="nofollow">here</a> and changed a little bit:</p>
  
  <pre><code>PostItem postItem = this._email.Application.CreateItem(OlItemType.olPostItem);
  postItem.MessageClass = "IPM.Note";
  PropertyAccessor pa = postItem.PropertyAccessor;
  pa.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", -1);
  postItem.Save();
  
  NameSpace session = postItem.Session;
  string postItemEntryID = postItem.EntryID;
  Marshal.ReleaseComObject(postItem);
  Marshal.ReleaseComObject(pa);
  
  MailItem newMessage = session.GetItemFromID(postItemEntryID) as MailItem;
  newMessage.BCC = this._email.BCC;
  newMessage.Body = this._email.Body;
  newMessage.BodyFormat = this._email.BodyFormat;
  newMessage.CC = this._email.CC;
  newMessage.HTMLBody = this._email.HTMLBody;
  
  //Hard coded path just for illustration
  newMessage.SaveAs("C:\\Temp\\MSG\test.msg", OlSaveAsType.olMSG); 
  </code></pre>
  
  <p>The code above creates a postitem object, set some of the properties and save to the path correctly, but it has the following problems:</p>
  
  <ol>
  <li><p>After executing <em>postItem.save</em>, to create the postitem message, it creates a read message in inbox folder</p></li>
  <li><p>After saving the messages, I have compared the files and the size where significant, the original message size was 580kb and the postitem saved message was 52kb. It seems it did not make a copy of the message</p></li>
  <li><p>It lost some of the of the images embedded in message, such as signature images, showing a red X in place.</p></li>
  </ol>
  
  <p>How can I get/create a message, with the exact message content, recipients, attachments, properties, etc (clone kind) with sent state, without creating another message inside inbox folder? </p>
  
  <p>Thank you</p>