New Mail Item Event

N

Neetu

I am creating a outlook add-in .on clicking on any custom folder created by
our add-in, we are opening windows forms.
according to requirement , if some exception occours, we are providing a
link button on errror form ( a window form with link button). on clicking on
link we have to send mail from outlook.
I am opening a mail item inside outlook programmatically. I m doing this like.

MailItem lobjNewMailitem =
(MailItem)Application.CreateItem(OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Application lobjApplication =
this.Application;
Microsoft.Office.Interop.Outlook.Inspector lobjInspector;
lobjInspector = lobjApplication.Inspectors.Add(lobjNewMailitem);
lobjNewMailitem = (MailItem)lobjInspector.CurrentItem;

lobjInspector.Activate();
lobjInspector.Display(lobjNewMailitem);

above code work fine if in case no other custom folder is opened inside
outlook.
eg -> when user first time open outlook and if exception occurs.

however soppose , if already other custom winform is opened like "Filter
form" ( one of the windows form )
this code doesn't work..

it says

"A dialog Box is open. close it and try again"

Inside code before displaying new mail item , i m explicitly closing all
possible forms like in our case we have 2 forms. so i m checking for them and
closing all.
still I m getting this exception.
I am using c#, and VSTO for outlook 2007

any suggesstion would be g8 help.!!
 
K

Ken Slovak - [MVP - Outlook]

If you have a modal form open in your addin you can't open a new item until
that form is closed or hidden. It's the same in any language you use (C#,
VB.NET, VB6, C++, etc.).

You can either hide or close your form when you want to open an Outlook
item.
 
N

Neetu

Yes Ken. That Y before opening ne main item, i m explicity closing all
possible forms. we have total 2 forms inside our project. still i m getting
this error message.
Is there any way to find any open modal form inside outlook?
 
K

Ken Slovak - [MVP - Outlook]

Hmm, see if it's any better if you don't use an Inspector at all when you
create the mail item, something like this:

MailItem lobjNewMailitem =
(MailItem)Application.CreateItem(OlItemType.olMailItem);

lobjNewMailItem.Display(false);

If Outlook is actually displaying an error or warning message that could
also be the problem. In that case about all you can do is to make sure the
error doesn't occur with lots of checking to prevent the error in the first
place.
 
N

Neetu

Hi Ken,

I found some other alternative . directly sending mail .
lobjNewMailItem.send();

Ken, is there any way to find where outlook is in offline or online..
so that if I fire this statement i can give appropriate message and save the
message in his/her mail box.
 
K

Ken Slovak - [MVP - Outlook]

Sure. In Outlook 2007 you have a couple of things you can check:

NameSpace.ExchangeConnectionMode
NameSpace.Offline

Review the Object Browser help on those properties.
 
N

Neetu

Hey Ken, thanks a lot.

Ken Slovak - said:
Sure. In Outlook 2007 you have a couple of things you can check:

NameSpace.ExchangeConnectionMode
NameSpace.Offline

Review the Object Browser help on those properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top