Reputation: 10590
My requirement is that i need to develop a web app , (it is mandatory to be a web app).
This app lists the outlook templates that has been saved in a specific directly.
Beside each template, there is a load button, you can say a load link if you want When the agent (client) clicks it, the outlook should open with that template.
I am trying to open the outlook from my asp.net application. when i click on my button, i execute this code
Microsoft.Office.Interop.Outlook._MailItem oMailItem2 = oApp.CreateItemFromTemplate(templateFilePath);
oMailItem2.Display(true);
It is working on my machine, but when i deploy it on the server, i got this error:
Request timed out.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request timed out.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Request timed out.]
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
It seems a very general error, what could be the problem please? how can I diagnosis it?
The body of the message in my case must be a html, not text. that is why i am not able to mailto
like this
<a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
Upvotes: 0
Views: 1028
Reputation: 12731
So you have a .msg file on the server, and you want to edit it and transmit it to users.
1) edit your template
https://www.google.it/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=c%23+edit+.msg+file
there are many 3rd party tools that can help to edit a .msg files
2. Send it to the user
using (FileStream fs = File.OpenRead(path))
{
int length = (int)fs.Length;
byte[] buffer;
using (BinaryReader br = new BinaryReader(fs))
{
buffer = br.ReadBytes(length);
}
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", Path.GetFileName(path)));
Response.ContentType = "application/" + Path.GetExtension(path).Substring(1);
Response.BinaryWrite(buffer);
Response.End()
}
Upvotes: 1
Reputation: 3884
The basic problem here is that you are trying to mix client and server logic in one application. Opening an Outlook window from an ASP.NET application server side is a very bad idea - IIS application pools are not allowed to interact with a user desktop (starting from Windows Vista or Windows Server 2008 they run in Session 0 which does not have a visible desktop available). So the Outlook window opens, but no one will ever see it. I assume that if it's a modal window it blocks the parent thread causing the timeout, but I'm not sure as I haven't had a chance to check it. On your development machine you have an IIS Express instance which runs in the same session as the current user and that's why you can see the Outlook window. The request is probably hanging for the whole time you interact with the Outlook dialog.
I understand that you are under time pressure so the only recommendation I have for you for now is to install on your client machine IIS Express (you may get it from here: http://www.microsoft.com/en-us/download/details.aspx?id=34679) and run your application from it. BUT in the meantime rewrite this logic - either create a web form to allow the user to compose an email and then use SmtpClient
class to send it for him or use mailto url that shoudl open Outlook window with valid data in it.
Upvotes: 0
Reputation: 12731
I think you're falling into this problem: have you ever tried logging into your Pc as Marco, and then setting up Outlook with your account.
Then, if you log as a different user, Outlook must be properly configured with his email account.
Actually, when IIS launches you asp.net application, it is living into a "no user" session, and no set is available for Outlook.
Maybe, your debug program worked because it was launched into a normal "Marco" session.
Create a real User (i.e. "Server Admin"), login with that user into the server, and configure Outlook
Open IIS, take the Application Pool of your application, chooes "Advanced settings" and then set "Application pool identity" to a "Custom account".
I hope this is enough to make your program work.
Upvotes: 1
Reputation: 49455
Marco, as I already wrote to you at Retrieving the COM class factory for component with CLSID error: 80070005 Access is denied
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
As a workaround you can use the low-level API - Extended MAPI. Or any other third-party wrappers around that API (for example, Redemption).
Upvotes: 2