Is it possible to set a message as sent programatically?

Add-in Express™ Support Service
That's what is more important than anything else

Is it possible to set a message as sent programatically?
outlook add in 
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hello!
I am currently developing an outlook addin in c#
My purpose is to create a message, use a web service to send it and move it to a folder named "Sent By Web Service".
Everything works except that the message in that forder "Sent By Web Service" looks like a draft. I want it to look like a sent message ( not sendable when opened)
My question is to know if it is possible to set a message as sent programatically.
Thanks
Posted 15 Mar, 2010 10:58:41 Top
Andrei Smolin


Add-in Express team


Posts: 18828
Joined: 2006-05-11
Hello Ndayongeje,

To achieve this, you'll have to dwell into Extended MAPI. Unfortunately, I cannot tell you what MAPI properties make the e-mail look sent. You can use Outlook Spy (please google for it) to find out those MAPI properties.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Mar, 2010 11:47:22 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hello Andrei.
The property i found id bool MailItem.Sent, but this one is readonly.
Posted 15 Mar, 2010 12:26:25 Top
Andrei Smolin


Add-in Express team


Posts: 18828
Joined: 2006-05-11
Ndayongeje,

What you found is a property in the Outlook object model. What i talked about was MAPI properties available via Extended MAPI. Note that some properties in the Outlook object model do have their Extended MAPI equivalents. A sample of such a property is MailItem.SentOn, accordong to the Outlook VBA help reference its equivalent is PR_CLIENT_SUBMIT_TIME. And MailItem.Sent doesn't have a correspoding MAPI property. You need to study MAPI properties using Outlook Spy. Then you will have to choose the way to access the MAPI properties. You can do this via our free http://www.add-in-express.com/products/mapi-store-events.php, Outlook Redemption, MAPI33 or force your way through Extended MAPI yourself.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Mar, 2010 06:15:47 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin,
i continued searching and found the following (below my message).
It seems to answer to my question but i got lost in it.
how to understand this piece of code
<<<<<<<<<<
ExtendedPropertyType msSentFlag = new ExtendedPropertyType();

PathToExtendedFieldType epExPathmc = new PathToExtendedFieldType();

epExPathmc.PropertyType = MapiPropertyTypeType.Integer;

epExPathmc.PropertyTag = "0x0E07";

msSentFlag.ExtendedFieldURI = epExPathmc;

msSentFlag.Item = "0";
>>>>>>>>>>>>>>>>
found on
http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/845aa9bf-55d4-4fde-aecf-74ca6bc03a64

Here is the full text where i took that piece of code.

You need to look at setting a couple of Extended Mapi properties as well such as PR_Client_Submit_Time and PR_Message_Delivery_Time. You might also want to set the message flags so it appears as Sent if your not already doing so eg




Code Snippet
CreateItemType ciCreateItemRequest = new CreateItemType();

ciCreateItemRequest.MessageDisposition = MessageDispositionType.SaveOnly;

ciCreateItemRequest.MessageDispositionSpecified = true;

ciCreateItemRequest.SavedItemFolderId = new TargetFolderIdType();

DistinguishedFolderIdType ibInbox = new DistinguishedFolderIdType();

ibInbox.Id = DistinguishedFolderIdNameType.inbox;

ciCreateItemRequest.SavedItemFolderId.Item = ibInbox;

ciCreateItemRequest.Items = new NonEmptyArrayOfAllItemsType();

MessageType wsMessage = new MessageType();

wsMessage.ToRecipients = new EmailAddressType[1];

wsMessage.ToRecipients[0] = new EmailAddressType();

wsMessage.ToRecipients[0].EmailAddress = "snd@yourdomain.com.au";

wsMessage.ToRecipients[0].Name "The Sender";

wsMessage.Subject = "Fried Eggs and Ham";

wsMessage.From = new SingleRecipientType();

wsMessage.From.Item = new EmailAddressType();

wsMessage.From.Item.EmailAddress = "rcd@yourdomain.com.au";



ExtendedPropertyType msSentFlag = new ExtendedPropertyType();

PathToExtendedFieldType epExPathmc = new PathToExtendedFieldType();

epExPathmc.PropertyType = MapiPropertyTypeType.Integer;

epExPathmc.PropertyTag = "0x0E07";

msSentFlag.ExtendedFieldURI = epExPathmc;

msSentFlag.Item = "0";



ExtendedPropertyType msClientSubmit = new ExtendedPropertyType();

PathToExtendedFieldType epExPathcs = new PathToExtendedFieldType();

epExPathcs.PropertyType = MapiPropertyTypeType.SystemTime;

epExPathcs.PropertyTag = "0x0039";

msClientSubmit.ExtendedFieldURI = epExPathcs;

msClientSubmit.Item = "2008-10-10T01:00:00Z";



ExtendedPropertyType rsRecievedTime = new ExtendedPropertyType();

PathToExtendedFieldType epExPathrt = new PathToExtendedFieldType();

epExPathrt.PropertyType = MapiPropertyTypeType.SystemTime;

epExPathrt.PropertyTag = "0x0E06";

rsRecievedTime.ExtendedFieldURI = epExPathrt;

rsRecievedTime.Item = "2008-10-10T01:00:00Z";




wsMessage.ExtendedProperty = new ExtendedPropertyType[3];

wsMessage.ExtendedProperty[0] = msClientSubmit;

wsMessage.ExtendedProperty[1] = msSentFlag;

wsMessage.ExtendedProperty[2] = rsRecievedTime;

ciCreateItemRequest.Items.Items = new ItemType[1];

ciCreateItemRequest.Items.Items[0] = wsMessage;

CreateItemResponseType crCreateItemResponse = esb.CreateItem(ciCreateItemRequest);
Posted 16 Mar, 2010 10:45:28 Top
Andrei Smolin


Add-in Express team


Posts: 18828
Joined: 2006-05-11
Hi Ndayongeje,

That code utilizes ExchangeWebSerices, it does not relate to using Outlook.

In my previous post I forgot to mention that in Outlook 2007 and higher, you can use the PropertyAccessor property/class which is yet another Extended MAPI wrapper.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Mar, 2010 11:00:40 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin!
Thanks for the information you gave, now i hope i am close to the answer
Need to find the right property index. Don`t you know where they are defined. For example
0x007D001E is for headers and the headers can be obtained as follows:
mailMessage.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")
Posted 16 Mar, 2010 12:50:51 Top
Andrei Smolin


Add-in Express team


Posts: 18828
Joined: 2006-05-11
Hi Ndayongeje,

Please see http://msdn.microsoft.com/en-us/library/cc765775.aspx. I'm sorry, I cannot give you a more definite URL.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Mar, 2010 13:18:11 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin,
I continued searching and found the following
<<<
PidTagMessageFlags (0x0E070003)
When a client calls the IMessage::SubmitMessage method to send the message, the message store provider makes a copy of it for the MAPI spooler and updates this property by setting the MSGFLAG_SUBMIT flag. The message store provider also sets MSGFLAG_UNSENT if it is not yet set. MSGFLAG_SUBMIT indicates that SubmitMessage has been called, beginning the send process, and that the message is now read-only to the client. MSGFLAG_UNSENT indicates that the MAPI spooler is handling the message. If the send process is canceled, the message store provider resets this flag.
----------
in my code i can get that property and follow its changes

Outlook.PropertyAccessor pa =newEmail.PropertyAccessor;
int c = (int)pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003");
MessageBox.Show(c + " "); // shows 8 - the MSGFLAG_UNSENT value
pa.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003", 0x00000000); // fails

Outlook.MailItem m = (Outlook.MailItem)newEmail.Move(MyFolder);
pa = m.PropertyAccessor;
c = (int)pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003");
MessageBox.Show(c + " "); // shows 24 two flags are set including the MSGFLAG_UNSENT
pa.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003", 0x00000011); // fails again
Am i doing it wrong?
Any idea?
Posted 17 Mar, 2010 09:48:45 Top
Andrei Smolin


Add-in Express team


Posts: 18828
Joined: 2006-05-11
Hi Ndayongeje,

Please check whether you have read/write access to these flags at http://msdn.microsoft.com/en-us/library/cc839733.aspx.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Mar, 2010 10:06:30 Top