Solved

Outlook Exception office interop

Posted on 2010-11-12
4
1,385 Views
Last Modified: 2016-02-06
Hello
I have some code that lauches an email (Microsoft Outlook) and add the emailadress, subject, attachment and body


As soon as I the code hits Outlook.Application outlookApp = new Outlook.Application();
it throws an exception only if Microsoft outlook was already open.

If outlook wasn't open on the user machine all works welol.
Any idean how I can resolve this?I know I can ask the user to close the app, but that is ionconvenient

Thanks
Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

message.Subject = “subject “
message.Recipients.Add(“someone@email.com”);

message.Body = “”;

int attachmentLocation = 1;


message.Attachments.Add(“” + ConfigurationSettings.AppSettings["Atachments"] + “Course Schedules for “ + lblProviderName.Text + “.xls”, Outlook.OlAttachmentType.olByValue,

attachmentLocation, “Course Schedules for “ + lblProviderName.Text + “.xls”);

message.Display(true);

Open in new window

0
Comment
Question by:xav056
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 500 total points
ID: 34122931
This may help. It discusses checking if Outlook is running and if so, use GetObject() to get to it.

http://www.eggheadcafe.com/software/aspnet/35993966/handling-applicationquit-event.aspx

Gary Davis
0
 
LVL 9

Author Comment

by:xav056
ID: 34123480
looks promising but I am getting an exception
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
as soon as i call GetActiveObject("Outlook.Application")

any ideas?

thanks
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 34123556
Try this article:

"GetObject or GetActiveObject cannot find a running Office application"

http://support.microsoft.com/kb/238610

Or google your error 0x800401E3.

Gary
0
 
LVL 10

Expert Comment

by:cdebel
ID: 41452533
I know this question was asked long time ago, but the only thing i see in KB 238610 is a partial answer.

I would add: Never underestimate your customer.  They may very well run an Evaluation Version of Outlook, expired, and for some reason they have managed to "make it work anyway"... but still, you will get this error (0x800401E3).  

Just found out... Thanks customer!  Lost 500$ trying to solve a problem that would have cost 110$ if the customer was not so cheap.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question