'C# Outlook Plugin - Create new item into Sent Box without send that email
I'm writing a plugin for outlook, I want to create new item into Sent Box but i don't want to send it, just save it to Sent Box.
Pls, help me!
Solution 1:[1]
Outlook Object Model will not, generally, let you create a message in the sent state - MailItem.Sent
property is read-only. Even on the MAPI level (C++ or Delphi), MSGFLAG_UNSENT
bit can be removed from the PR_MESSAGE_FLAGS
property only before the message is saved for the very first time. The only kind of item created by OOM in the sent state is a post item, so in theory, you can create a post item, save it, reset its MessageClass
property to "IPM.Note",
dereference it, reopen by the entry id - you will now have a MailItem in the sent state. You will not have to set all the sender and recipient properties (about a dozen of them) and remove post specific properties - take a look at a sent message with OutlookSpy (I am its author - click IMessage button).
If using Redemption (I am also its author - any language) is an option, it can create a fake sent message easily:
Set MySession = CreateObject("Redemption.RDOSession")
MySession.MAPIOBJECT = Application.Session.MAPIOBJECT
Set Folder = MySession.GetDefaultFolder(olFolderSentMail)
Set msg = Folder.Items.Add("IPM.Note")
msg.Sent = True
msg.Recipients.AddEx "The user", "[email protected]", "SMTP", olTo
msg.Sender = MySession.CurrentUser
msg.SentOnBehalfOf = MySession.CurrentUser
msg.subject = "Test sent message"
msg.Body = "test body"
msg.SentOn = Now
msg.ReceivedTime = Now
msg.Save
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |