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:
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);
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:
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;
}