0
votes

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))

1
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
The user account you are using doesn't have correct user rights - Tsukasa

1 Answers

1
votes

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!