0
votes

When programmatically create a new e-mail following code is used:

solutionRoot = rootStoreFolder.Folders.Add("MyInboxFolder", Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; 
folder = solutionRoot.Folders["MyFolderName"] as Outlook.Folder;
subFolder = folder.Folders["MyFolderSubName"] as Outlook.Folder;

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

mailItem.Subject = "TestSubject";
mailItem.To = "[email protected]";                           
mailItem.Body = "This is the message.";
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(false);
mailItem.Move(subFolder);

The result is the creation of a new message with a send button placed into folder subFolder.

The question is: what code should I use in order to create an new mail item into the folder called subFolder, but not a new e-mail ready to be sent, an e-mail which has been received and read already, an existing e-mail.

1
Hi LucianC, please try to add some more context to your question, maybe this guide helps: stackoverflow.com/help/how-to-askreto

1 Answers

0
votes

Outlook will not let you create a sent message out of the box (MailItem.Sent property is read-only). The only item created in the sent state is a post item - you can create an olPostItem object (PostItem), then change its MessageClass property back to IPM.Note. You will also need to delete the PR_ICON_INDEX property to make sure it is shown correctly. Note that sent/received dates cannot be set using OOM.

If using Redemption is an option, the following script (VB) will create a fake received message addressed to the current user:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Inbox = Session.GetDefaultFolder(olFolderInbox)
  set Msg = Inbox.Items.Add
  Msg.Sent = true
  set CU = Session.CurrentUser
  set recip = Msg.Recipients.AddEx(CU.Name, CU.SmtpAddress, "SMTP", olTo)
  Msg.Subject = "fake received message"
  Msg.Body = "just a test"
  vSenderEntryId = Session.AddressBook.CreateOneOffEntryID("Joe The Sender", "SMTP", "[email protected]", false, true)
  set vSender = Session.AddressBook.GetAddressEntryFromID(vSenderEntryId)
  Msg.Sender = vSender
  Msg.SentOnBehalfOf = vSender
  Msg.SentOn = Now
  Msg.ReceivedTime = Now
  Msg.Save