Get Outlook's new mail item before sending

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

Get Outlook's new mail item before sending
 
Oliver D.




Posts: 54
Joined: 2005-02-03
How can I get the new mail entries from the mail inspector by clicking on a custom button BEFORE sending the mail?

Like:
- Open new mail inspector
- enter TO, SUBJECT, BODY, etc.
- Click Custom Button
- Now, read all those information in popup dialog
- Then send the mail.

Thanks guys.
Posted 29 Mar, 2005 10:41:07 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Oliver. Try the following code:

Outlook._MailItem mail = null;
Outlook._Inspector inspector = OutlookHost().ActiveInspector();
try
{
if (inspector.CurrentItem is Outlook._MailItem)
{
mail = inspector.CurrentItem as Outlook._MailItem;
string TO = mail.To;
string SUBJECT = mail.Subject;
string BODY = mail.Body;
}
}
finally
{
if (inspector != null)
Marshal.ReleaseComObject(inspector);
if (mail != null)
Marshal.ReleaseComObject(mail);
}
Posted 29 Mar, 2005 18:37:46 Top
Oliver D.




Posts: 54
Joined: 2005-02-03
Thank you Sergey.

I used ActiveExplorer instead of ActiveInspector. Duhh!

Thank you so much AGAIN for all your excellent support!
Your premium support is worth every penny!!

Posted 30 Mar, 2005 09:36:49 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Oliver, this is the code with ActiveExplorer.

object item = null;
Outlook._MailItem mail = null;
Outlook.Selection selection = null;
Outlook._Explorer explorer = OutlookHost().ActiveExplorer();
try
{
selection = explorer.Selection;
if (selection != null)
{
if (selection.Count > 0)
{
item = selection.Item(1);
if (item is Outlook._MailItem)
{
mail = item as Outlook._MailItem;
string TO = mail.To;
string SUBJECT = mail.Subject;
string BODY = mail.Body;
}
}
}
}
finally
{
if (item != null)
Marshal.ReleaseComObject(item);
if (selection != null)
Marshal.ReleaseComObject(selection);
if (mail != null)
Marshal.ReleaseComObject(mail);
if (explorer != null)
Marshal.ReleaseComObject(explorer);
}
Posted 30 Mar, 2005 15:24:38 Top
Oliver D.




Posts: 54
Joined: 2005-02-03
That's what I used previously realizing that I should have used the ActiveInspector instead of ActiveExplorer in my code. The "Duhh!" was for myself. :-)

Thanks again.
Posted 30 Mar, 2005 16:28:10 Top