siddu
siddu

Reputation: 51

Failing to create an email with outlook interop when outlook has already been opened

How do you open an outlook window? I tried the code below but this doesn't work when an instance of outlook is already running -

System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

int processCount = processes.Length;
if (processCount != 0)
{
    **outlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;** this is throwing the below error **
}
else
{
    outlookApp = new Microsoft.Office.Interop.Outlook.Application();
}

And I got:

Error:
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

Can someone please give an alternate approach or changes to the above code?

Upvotes: 1

Views: 1743

Answers (2)

m.t.bennett
m.t.bennett

Reputation: 1320

Putting in my 2 cents as I'm having the same issue.

It seems that Visual Studio normally being run as an Administrator and Outlook being run with user privileges is the problem.

If close Outlook and run the code it works fine.

If I run the application outside of visual studio (from the Bin folder) with Outlook running it also works fine.

If I run Outlook as administrator and run the application in Visual Studio it works fine.

I haven't yet found a workaround for getting the instance of the Outlook Application class if Outlook is running but on different privileges.

Upvotes: 1

MikroDel
MikroDel

Reputation: 6735

try this How to: Programmatically Send E-Mail

Upvotes: 0

Related Questions