How to create temp mailitem.
-
Mittwoch, 20. Juni 2012 19:37
I am writing the ribbon for outlook. And i should modify the content of the selected mail. The code i get the current mail item is:
[CODE]
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
var application = Globals.ThisAddIn.Application;
mail = application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
Outlook.Selection selection = application.ActiveExplorer().Selection;
mail = selection[1] as Outlook.MailItem;[/CODE]
When i modify the content of mail. The current of the mail which show to the users is changed too. How can i avoid that thing? Such as use the temp mail item or somethings... ?
Alle Antworten
-
Mittwoch, 20. Juni 2012 19:47
Why exactly do you need a temporary message?
If it is a temporary message, why do you modify it?
Dmitry Streblechenko (MVP) http://www.dimastr.com/redemption
Redemption - what the Outlook
Object Model should have been
Version 5.3 is now available!
-
Mittwoch, 20. Juni 2012 19:52either modify contents of temporary mail or the one that is selected, do not mix them
-
Mittwoch, 20. Juni 2012 20:02Either use a different variable for the item you create or for the item in the Selection. Don't use the same one for both. Of course the current mail the user is viewing will change, you're modifying it.var application = Globals.ThisAddIn.Application;
mail = application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
Outlook.Selection selection = application.ActiveExplorer().Selection;
mail1 = selection[1] as Outlook.MailItem;"se7enbit" <=?utf-8?B?c2U3ZW5iaXQ=?=> wrote in message news:f9dfcfbf-f3ad-4e7e-b0e2-059f9f59d94f...I am writing the ribbon for outlook. And i should modify the content of the selected mail. The code i get the current mail item is:
[CODE]
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
var application = Globals.ThisAddIn.Application;
mail = application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
Outlook.Selection selection = application.ActiveExplorer().Selection;
mail = selection[1] as Outlook.MailItem;[/CODE]
When i modify the content of mail. The current of the mail which show to the users is changed too. How can i avoid that thing? Such as use the temp mail item or somethings... ?
Ken Slovak MVP - Outlook -
Donnerstag, 21. Juni 2012 02:44
Thank all for relying.
Because i just want to use that objMailItem to use all its properties. And i modify them to print but not want to change the content of current mail because i use Thread so that now my problem is the content of current mail constantly changing. I want have temp mailItem or somethings that i can modify it but do not affect to the current showing mailItem.
Example:
string tempHTML = objMailItem.HTMLBody; objMailItem.HTMLBody = htmlOr; bodyOr = objMailItem.Body; objMailItem.HTMLBody = tempHTML ;
htmlOr actually is a objMailItem.HTMLBody but has been modified. And i want to get the content of the modified Body. Anyways to solve this?
- Bearbeitet se7enbit Donnerstag, 21. Juni 2012 03:07
-
Donnerstag, 21. Juni 2012 04:04
Use MailItem.Copy (returns a new MailItem object) and modify it instead.
Dmitry Streblechenko (MVP) http://www.dimastr.com/redemption
Redemption - what the Outlook
Object Model should have been
Version 5.3 is now available!
-
Donnerstag, 21. Juni 2012 10:24
Thank you very much :D.
-
Donnerstag, 21. Juni 2012 13:07Just make sure that you aren't calling anything in the Outlook object model from a background thread, that's not supported and will cause Outlook to hang or crash. Use threading for anything but the Outlook object model."se7enbit" <=?utf-8?B?c2U3ZW5iaXQ=?=> wrote in message news:f577c128-639b-4b6b-b736-08a1f1a6fbc4...
Thank all for relying.
Because i just want to use that objMailItem to use all its properties. And i modify them to print but not want to change the content of current mail because i use Thread so that now my problem is the content of current mail constantly changing. I want have temp mailItem or somethings that i can modify it but do not affect to the current showing mailItem.
Example:
string tempHTML = objMailItem.HTMLBody; objMailItem.HTMLBody = htmlOr; bodyOr = objMailItem.Body; objMailItem.HTMLBody = tempHTML ;
htmlOr actually is a objMailItem.HTMLBody but has been modified. And i want to get the content of the modified Body. Anyways to solve this?
Ken Slovak MVP - Outlook

