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
About the read and write i got the following answers
Answerer:
You have to set the property before you call SaveChanges the first time. From the docs:
" The message is still being composed. It is saved, but has not been sent. The client or provider has read/write access to this flag until the first IMAPIProp::SaveChanges call and read-only thereafter. If a client doesn't set this flag by the time the message is sent, the message store provider sets it when IMessage::SubmitMessage is called. Typically, this flag is cleared after the message is sent. "
-------
Me:
I did not call the SaveChanges() anywhere .
I created a new message newEmail programmatically, manually filled it with dat a: To, Subject; Body.
I use my buttonon toolbar to reach the code that i showed bellow.
The code does:
1) get the property value of the message being composed (The value is 8 - the flag MSGFLAG_UNSENT)
2) try to set that property with the value 0. This fails (The exception message is "The operation failed")
3) move the new message to another folder
4) get the property value of the message moved file (The value is 24 - the flag MSGFLAG_UNSENT and another one)
5) try to set that property with the value 16. This fails too(The exception message is "The operation failed")

Is here something to change, to add or something is wrong with the way i do it?
------
Answerer:
That must be the object model blocking the change then. If you created the message with MAPI you'd be able to set the flags appropriately before saving.
One option you have here is to build a real transport provider.
Posted 17 Mar, 2010 10:34:09 Top
Andrei Smolin


Add-in Express team


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

Outlook is sort of wrapper over Extended MAPI store. Like a client for a DB. And Extended MAPI is just another way to access the same DB. When you create an e-mail, it isn't saved to the DB and you cannot use Extended MAPI to access the e-mail. I assume, that when you save or move the e-mail, Outlook calls IMAPIProp::SaveChanges for you.

Regards from Belarus (GMT+2),

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




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin,
Probably i will not have read/write access to those flags. I used the MFCMAPI to do my tests of reading/writing properties. It can`t write them.
i finally decided to use posts. They can do what i need. After i sent the message via my web services, i create a post, fill it with needed data.
Here too i have a minor problem: It takes long(+- 3 minutes) before it becomes readonly.
But when a create a post using outlook user interface and post it, it becomes readonly instantly.

Here is the code i use:
//folder - is the mapi folder where to post to.
Outlook.PostItem post1 = folder.Items.Add(Outlook.OlItemType.olPostItem) as Outlook.PostItem;
post1.Subject = subject;
post1.BodyFormat = format;
post1.Body = body;
post1.Post();

Is this code missing something?
Posted 29 Mar, 2010 09:21:34 Top
Andrei Smolin


Add-in Express team


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

Try releasing post1 (Marshal.ReleaseComObject)after calling the Post method. Also, see the following article on our blog: Why to release COM objects in Office add-ins?

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Mar, 2010 12:18:41 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin,
What you say completely reflects the type of my problem
It is not matter of taking long (+- 3mins). Further tests showed me that i could wait more than 10 mins and nothing happens. But when i close and open outlook, i get it already readonly. Somewhere the object is not released.

I tryed the Marshal.ReleaseComObject(post1); but nothing happened

thanks
Posted 29 Mar, 2010 14:23:21 Top
Andrei Smolin


Add-in Express team


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

I suggest simplifying your code and carefully using Marshal.ReleaseComObject in the remaining part in order to pin down the issue. Just everything I wrote about releasing COM objects in a COM add-in may apply to your case: 1) using foreach instead of for; 2) not releasing collections belonging to the item; 3) not releasing the inspector that shows the item; 4) creating several COM objects pointing to the same item; etc. Also, if you intercept the item's events, try to disconnect from them as connecting to events creates hidden COM objects.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Mar, 2010 06:11:28 Top
Ndayongeje Dieudonne




Posts: 24
Joined: 2010-03-15
Hi Andrei Smolin,
You are pretty right!.
I have reference to the folder that i use during the whole session. I have to deal with this issue.
Because when i post to other folders and then release the post, the post becomes readonly instantly.
Thanks a lot!
Spacibo!
Posted 30 Mar, 2010 07:57:49 Top
Andrei Smolin


Add-in Express team


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

Congratulations!

Regards from Belarus (GMT+2),

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