Outlook formregion problem

R

Rolando Tonin

I’m Rolando Tonin, an italian engineer , and I’m developing an Outlook2007
AddIn in C# with Visual Studio 2008 and VSTO 3.0.
My AddIn contain a FormRegion linked to a specific MessageClass (i.e.:
IPM.Note.IdroesseTaskFaseBO). This FormRegion must display specific business
information when the user open an e-mail incoming from a SQL Server trigger.
This e-mail has a distinct Subject. When SQL Server trigger the e-mail I
can’t associate MessageClass (I use SPROC sp_send_dbmail that, unfortunately,
hasn’t a @parameter of this type). Conseguently I must associate the
MessageClass when the e-mail get in Outlook. For this I use NewMailEx event.
When this event is triggered I process the MailItem’s Subject and if it is
equal to my Subject I change the MessageClass property of the MailItem object
and save this. When the user open the InBox Message the Form Region appare
correctly.
This work fine if Outlook is open when the SQL Server trigger the e-mail.
Instead, if Outlook is closed, the e-mail, logically, is storaged on the
Exchange Server. When the user open Outlook the e-mail is downloaded from
Exchange Server but the NewMailEx is not called. Conseguenty when the user
open the e-mail this is displayed on the standard e-mail form….
I tried with Outlook Application ItemLoad event. I intercept the MailItem
change the MessageClass, save the MailItem but the e-mail is displayed on the
standard e-mail form. If the user close this form and reopen the e-mail this
time the FormRegion appare correctly. I don’t like to force the user to open
two times the e-mail before to get the correct FormRegion.
How can I resolve this problem?

Thanks in advance
 
K

Ken Slovak - [MVP - Outlook]

In your startup code scan the Inbox for unread messages and see if any need
to be changed to your custom MessageClass. You could also store a hidden
message in Inbox with a date of your last scan and use that to determine
which items in Inbox need to be checked.
 
R

Rolando Tonin

I've tried with this code but it's not work correctly:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
RemoveToolbar();
AddToolbar();
this.Application.NewMailEx += new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
CheckInBoxForNewEmails();
}

private void CheckInBoxForNewEmails()
{
Outlook.Folder inbox =
this.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox) as
Outlook.Folder;
if(inbox != null)
{
Outlook.Items itms = inbox.Items.Restrict("[Unread] = true");
foreach (Outlook.MailItem itm in itms)
{
if (itm.MessageClass != "IPM.Note.IdroesseTaskFaseBO" && itm.Subject !=
null && itm.Subject.Contains("Assegnazione attività Fase di Commessa"))
{
itm.MessageClass = "IPM.Note.IdroesseTaskFaseBO";
itm.Save();
}
}
}

It seems that CheckInBoxForNewEmails() is called before Outlook syncronize
with Exchange. What can I do?
Thanks in advance
Rolando
 
K

Ken Slovak - [MVP - Outlook]

Set a timer to fire once at an interval after your startup event handler. Do
the email check at that time. Or just wait for NewMailEx to fire and use
that to trigger the initial check.
 
R

Rolando Tonin

I resolved the problem using the Outlook.Items ItemAdd event. I set it after
call Restrict method and this work correctly.
Thanks
Rolando Tonin

Ken Slovak - said:
Set a timer to fire once at an interval after your startup event handler. Do
the email check at that time. Or just wait for NewMailEx to fire and use
that to trigger the initial check.




Rolando Tonin said:
I've tried with this code but it's not work correctly:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
RemoveToolbar();
AddToolbar();
this.Application.NewMailEx += new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
CheckInBoxForNewEmails();
}

private void CheckInBoxForNewEmails()
{
Outlook.Folder inbox =
this.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox)
as
Outlook.Folder;
if(inbox != null)
{
Outlook.Items itms = inbox.Items.Restrict("[Unread] = true");
foreach (Outlook.MailItem itm in itms)
{
if (itm.MessageClass != "IPM.Note.IdroesseTaskFaseBO" && itm.Subject
!=
null && itm.Subject.Contains("Assegnazione attività Fase di Commessa"))
{
itm.MessageClass = "IPM.Note.IdroesseTaskFaseBO";
itm.Save();
}
}
}

It seems that CheckInBoxForNewEmails() is called before Outlook syncronize
with Exchange. What can I do?
Thanks in advance
Rolando
 

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