Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I deployed my project on IIS 7.5. But got error on sending email through MS Outlook
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))

The related code below
C#
public void SendEmailthroughOutlook(string emailAddressTo, string sSubject, string sText) {
    Application app = new Application();  // Error when implement this line
    NameSpace ns = app.GetNamespace("mapi");
    //ns.Logon("Email-Id", "Password", false, true);
    MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem);
    message.To = emailAddressTo;
    message.CC = "";
    sSubject = "Subject: " + sSubject;
    message.Subject = sSubject;
    message.Body = sText;

    message.Send();
    ns.Logoff();
}

I also referred to asp.net - "Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) - Stack Overflow[^] and checked the DCOM Config tree, but I did not see any MS Office component there.
What's the proper solution for this problem? Thanks.

What I have tried:

Successful in VS2010 debugging, but failed as deployed in IIS
Posted
Updated 29-Feb-16 10:12am
v6
Comments
Philippe Mori 29-Feb-16 22:29pm    
Never use Office interop from a server. This is well known that Office automation is not intended for that purpose.

You can't use Outlook to send an email from a WebServer. First, you have to have Office installed on the server, but don't bother doing this. None of the Office applications are supported in a server (non-interactive) environment as Office applications do not support multiple requests at the same time. A web server is an example of this.

Why are you not using the built in mail classes[^] in the .NET Framework to send an email?
 
Share this answer
 
Comments
s yu 1-Mar-16 14:05pm    
DK: Thanks for your advisory. Then, I did the following:
1) Got the sample code from http://www.codeproject.com/Articles/38750/A-Simple-But-Effective-Way-to-Send-an-Email-using.
2) Configged IIS7.5's SMTP email by referring to the procedure in https://technet.microsoft.com/en-us/library/cc772058(v=ws.10).aspx. In the configuration, I did: a) entered my email as the E-mail Address, b)entered localhost as the SMTP Server, c) checked on Use localhost, and d) Used Not required for Authentication Settings.
However, when I debugged the code, I got
System.Net.Mail.SmtpException: {"Failure sending mail."}
InnerException: {"Unable to connect to the remote server"}
Could you provide your additional advisory? Thanks again.
Dave Kreskowiak 1-Mar-16 17:01pm    
I couldn't tell you. I have no experience with that mail server so I couldn't tell you if your configuration is correct or not or even how to tell!
Access is denied.

Your application does not have access to the resources. Make sure, your program is supported to navigate and access the resources in the directory. Since you are talking about IIS, read this thread on IIS forums: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) : The Official Microsoft IIS Forums[^], which says, you need to provide Administrator privileges to the programs.

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) in vb.net[^]
c# - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED) - Stack Overflow[^]

Anyhow, if you are on a hosting environment provided by a third-party company. Then you would have to communicate with their representative and ask them to allow your application to use the resources; provide the access.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900