Trying to open the new mailItem inspector form within a custom Win

  • Thread starter Thread starter Naji
  • Start date Start date
N

Naji

Good evening everybody,

I am working on a VST add-in. I am using C#, Outlook 2007 and VS2008

I have a Toolbar button that, when clicked, opens a windows form. This part
works fine. However, what I am having a problem with is trying to,
programmatically, open a new mailItem inspector by clicking on a button that
resides on the windows form.
I need to do it in this fashion to:
1- be able to populate the mailitem properties using the winForm fields
2- avoid recreating all the functionality(attachment,spell check, follow
up, address book, etc ) that is already built into the mail inspector window

My question: is it possible to open a new Message Inspector from withing a
windows form that is part of an Outlook add-in?
If the answer is yes, and I hope so, How would you do it?



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is what I have in place so far:

public void CreateNewMail(string subject)
{
Outlook.MailItem mail = null;
Outlook.Application m_Outlook = null;

try
{
m_Outlook = Globals.ThisAddIn.Application;

mail =
(Outlook.MailItem)m_Outlook.CreateItem(Outlook.OlItemType.olMailItem);
mail.Subject = subject;
mail.Display(false);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (mail != null)
Marshal.ReleaseComObject(mail);
}
}


Thank you for your time and effort.
 
What's wrong with using mail.Display()? Just create the item when your
button is clicked and call Display() on the item. If you want a handle to
the Inspector for the item just use mail.GetInspector().
 
Good morning Ken,

Thank you for your response.

Nothing is wrong with [mail.Display], if you take a look at the code snippet
I included in my initial post, I am making use of it. The problem, though, is
that in order to get a reference to a new mailItem, you need to use
[This.Application.CreateItem...], and since I am making the call from within
a winform, [This.Application] would not work. To solve this problem, I am
using [Globals.ThisAddIn.Application], but this call throws an exception and
that is my problem.

So once I successfully create a mailItem, I would definitely call the
[Display ] method on that Item.

Thank you Ken.
 
What exception are you getting? I call my "global" Outlook.Application
object from lots of places in my code, including from within Windows forms
with no exceptions.
 
I got an error "A dialog box is open. Close it and try again."

My code here:

Outlook.Application thisApp = Globals.ThisAddIn.Application;
Outlook.NameSpace ns = thisApp.GetNamespace("MAPI");
Outlook.MAPIFolder appointmentFolder = thisApp.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderCalendar);

object o =
ns.GetItemFromID("000000009408AECE65C0E84BAB4CE89B19E6944FA4642100",
appointmentFolder.StoreID);

Outlook.AppointmentItem appointmentItem = (Outlook.AppointmentItem)o;
appointmentItem.Display(false); // or true

Jason
 
I don't see where that code is creating the appointment item, but what line
triggers the dialog box open message?

Is the thisApp object valid when you get it? Have you looked at it in debug
mode?

If worst came to worst you could always just set your Outlook.Application
object before calling Show on your form from wherever the form is called.

Also, if you have a NameSpace object why use thisApp.Session? Just use ns
instead.
 
Hi,
I am facing same issue while opening a new mail message from windows application. My windows form open through outlook only.

Have you got any solution for this?
Please share.

Thank you,
Manoj

my email id is (e-mail address removed)
Good evening everybody,

I am working on a VST add-in. I am using C#, Outlook 2007 and VS2008

I have a Toolbar button that, when clicked, opens a windows form. This part
works fine. However, what I am having a problem with is trying to,
programmatically, open a new mailItem inspector by clicking on a button that
resides on the windows form.
I need to do it in this fashion to:
1- be able to populate the mailitem properties using the winForm fields
2- avoid recreating all the functionality(attachment,spell check, follow
up, address book, etc ) that is already built into the mail inspector window

My question: is it possible to open a new Message Inspector from withing a
windows form that is part of an Outlook add-in?
If the answer is yes, and I hope so, How would you do it?



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is what I have in place so far:

public void CreateNewMail(string subject)
{
Outlook.MailItem mail = null;
Outlook.Application m_Outlook = null;

try
{
m_Outlook = Globals.ThisAddIn.Application;

mail =
(Outlook.MailItem)m_Outlook.CreateItem(Outlook.OlItemType.olMailItem);
mail.Subject = subject;
mail.Display(false);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (mail != null)
Marshal.ReleaseComObject(mail);
}
}


Thank you for your time and effort.
On Monday, May 12, 2008 9:03 AM Ken Slovak - [MVP - Outlook] wrote:
What's wrong with using mail.Display()? Just create the item when your
button is clicked and call Display() on the item. If you want a handle to
the Inspector for the item just use mail.GetInspector().




news:[email protected]...
On Monday, May 12, 2008 9:44 AM Naj wrote:
Good morning Ken,

Thank you for your response.

Nothing is wrong with [mail.Display], if you take a look at the code snippet
I included in my initial post, I am making use of it. The problem, though, is
that in order to get a reference to a new mailItem, you need to use
[This.Application.CreateItem...], and since I am making the call from within
a winform, [This.Application] would not work. To solve this problem, I am
using [Globals.ThisAddIn.Application], but this call throws an exception and
that is my problem.

So once I successfully create a mailItem, I would definitely call the
[Display ] method on that Item.

Thank you Ken.

"Ken Slovak - [MVP - Outlook]" wrote:
On Monday, May 12, 2008 11:06 AM Ken Slovak - [MVP - Outlook] wrote:
What exception are you getting? I call my "global" Outlook.Application
object from lots of places in my code, including from within Windows forms
with no exceptions.




news:[email protected]...
On Tuesday, June 17, 2008 9:30 AM Ken Slovak - [MVP - Outlook] wrote:
I don't see where that code is creating the appointment item, but what line
triggers the dialog box open message?

Is the thisApp object valid when you get it? Have you looked at it in debug
mode?

If worst came to worst you could always just set your Outlook.Application
object before calling Show on your form from wherever the form is called.

Also, if you have a NameSpace object why use thisApp.Session? Just use ns
instead.




news:D[email protected]...
 
Back
Top