0

I am trying to send mail from user's Outlook send folder with the following code.But it shows the following error: My code

try
{
    Outlook.Application oApp = new Outlook.Application();
    Outlook.NameSpace oNamespace = new Outlook.NameSpace("MAPI");
    Outlook.MailItem oMailItem =     (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
    oMailItem.HTMLBody = bd.Trim();

    oMailItem.Subject = sbj.Trim();
    Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(bccadd);
    oRecip.Resolve();
    oMailItem.Send();
    oRecip = null;
    oRecips = null;
    oMailItem = null;
    oApp = null;
}
catch (Exception ex)
{
    Response.Write("<script>alert('" + ex.Message + "');</script>");
    //string script = "<script>alert('" + ex.Message + "');</script>";
}

But I am getting the following error:

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

FaisalThayyil
  • 85
  • 1
  • 3
  • 14
  • similar: http://stackoverflow.com/questions/14019401/80070005-access-is-denied-when-asp-net-website-with-crystal-report-is-deployed-o – Alex van den Hoogen Mar 04 '14 at 13:20
  • If my understanding is correct, it looks like you're trying to load Outlook objects on your web server... just because the user is running the website on a browser on their computer, doesn't mean your ASP.NET code can use Outlook on their computer – freefaller Mar 04 '14 at 13:21
  • The user account you are using doesn't have correct user rights – Tsukasa Mar 04 '14 at 13:22

1 Answers1

1

You need to understand and at all times keep in mind that an ASP.NET page runs on the server, not the client computer. The web server executes the C# code you write (roughly speaking). The C# code (along with the ASPX files) produces the (HTML) content that is then sent to the client's browser.

You can not use that code to send an email through the user's Outlook installation. The code you wrote tries to send an email through the Outlook that's installed on the server!

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • Hello Dittmar ..Is there any way to send the mail from user outlook? in asp.net – FaisalThayyil Mar 04 '14 at 13:27
  • No. You could try your luck with client-side JavaScript. Or you could hope that Outlook is set as the default mail application and use a simple "mailto:" link. Is there a special reason why you need to use Outlook and not simply rely on the default mailer? – Thorsten Dittmar Mar 04 '14 at 13:45
  • If the mail goes from user outlook , he will have copy in his send items folder.this is mandatory from auditing point of view – FaisalThayyil Mar 04 '14 at 13:50
  • I don't use Outlook - I use Apple Mail. Now what? If you use a `mailto:` link, the user will have a "Sent" copy in *any* email program *he* decides to use, imagine that! And you can make it work, as opposed to your Outlook approach ;-) – Thorsten Dittmar Mar 04 '14 at 14:16