Click here to Skip to main content
14,976,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to send an email through Outlook 2010.

0) I'm on a DoD network and Outlook is connected to an Exchange server.

1) Outlook is open, and I'm currently logged in (we use CAC cards here for access, and we're using Active Directory).

I'm getting the following COM exception:

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

at the line indicated below:

C#
public void SendEmails(List<VMReportItem> list)
{
    OUTLOOK.Application  app;
    OUTLOOK.NameSpace    ns;
    OUTLOOK.MAPIFolder   inbox;
    OUTLOOK.AddressEntry currentUser;
    OUTLOOK.MailItem     mailItem;

    try
    {
        app         = new OUTLOOK.Application();
        ns          = app.GetNamespace("MAPI");
        inbox       = ns.GetDefaultFolder(OUTLOOK.OlDefaultFolders.olFolderInbox);

        // EXCEPTION THROWN HERE when I try to get the current user CurrentUser
        currentUser = app.Session.CurrentUser.AddressEntry; 

        if (currentUser.Type == "EX")
        {
            foreach (VMReportItem item in list)
            {
                mailItem = this.CreateOutlookMail(app, item);
                mailItem.Send();
                while (!mailItem.Sent)
                {
                    Thread.Sleep(1000);
                }
            }
        }
    }
    catch (Exception ex)
    {
    }
}


What I have tried:

I tried removing the currentUser code, but I get the same exception when the code tries to execute mailItem.Send(). HOWEVER, I do see a new window popup with the email I'm trying to send.

In the interest of completeness, the CreateMail method is shown below:

C#
blic OUTLOOK.MailItem CreateOutlookMail(OUTLOOK.Application app, VMReportItem item)
{
    StringBuilder body = new StringBuilder();
    body.AppendLine(item.Body).AppendLine();
    body.AppendLine(this.RecipientNotice).AppendLine();
    body.AppendLine(this.QuestionsNotice).AppendLine();

    OUTLOOK.MailItem  mail = app.CreateItem(OUTLOOK.OlItemType.olMailItem) as OUTLOOK.MailItem;
    mail.Subject = item.Subject;
    mail.To      = "myaddress@mydomain";
    mail.Body    = body.ToString();
    mail.Attachments.Add(System.IO.Path.Combine(this.ReportPath,item.Attachment));
    mail.Display(false);
    return mail;
}
Posted

1 solution

I think the problem is a group policy setting. To get around it, I'm using interop services to find the new email window and click the send button.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900