ItemSend Event Issues C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SteveHasel
    New Member
    • Aug 2007
    • 17

    ItemSend Event Issues C#

    I'm working in Visual Studio 2005 trying to use Outlook to create an email and display it for the user to edit and then send. I need to be able to check that the item in the ItemSend event is my item and not some other MailItem. Here is the jist of the code I am using so far:

    public partial class frmSendToPayrol l : Form
    {
    //...
    private MailItem oMailItem = null;
    Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass oApp = null;
    Microsoft.Offic e.Interop.Outlo ok.NameSpace oNS = null;

    //...

    private void btnButton_Click (object sender, EventArgs e)
    {
    //Create an email and open it up in Outlook
    oApp = new Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
    oApp.ItemSend += new ApplicationEven ts_11_ItemSendE ventHandler(oAp p_ItemSend);
    oNS = oApp.GetNamespa ce("MAPI");
    oNS.Logon(Missi ng.Value, Missing.Value, false, false);
    oMailItem = oApp.CreateItem (OlItemType.olM ailItem) as MailItem;
    oMailItem.BodyF ormat = OlBodyFormat.ol FormatHTML;
    oMailItem.HTMLB ody = CreateBody();
    oMailItem.Subje ct = "Some Subject";
    oMailItem.To = "someemail@emai l.com";
    oMailItem.Displ ay(false);
    }
    void oApp_ItemSend(o bject Item, ref bool Cancel)
    {
    if (((MailItem)(It em)) == oMailItem)
    CallSomeFunctio n();
    }

    }
    The problems I'm having now are that it lags really hard when trying to send the email and some times whatever is in the event actually runs, but sometimes it doesn't. I'm wondering if I'm doing something wrong or if there's something I'm missing. Any help would be appreciated.

    Thanks,
    Steve
Working...