Reputation: 25
I am trying to open an email in Outlook from within a .NET application. When I run everything on my local machine it works just fine. When I deploy out to an IIS8 server I get an error on loading of the page. Does Outlook need to be installed on the server as well as the local client or does it just need to be on the client? When I comment out the below code everything loads just fine.
using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;
protected void passdownBtn_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
{
SqlCommand comm = new SqlCommand("EXEC SvcGridEmail", conn);
conn.Open();
comm.ExecuteNonQuery();
string body = (string)comm.ExecuteScalar();
conn.Close();
string address = "[email protected]";
string time = String.Format("{0:MM/dd/yy HH:mm}", System.DateTime.Now);
string subject = "Service Jobs Passdown @ " + time;
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = address;
oMailItem.HTMLBody = body;
oMailItem.Subject = subject;
oMailItem.Display(true);
}
}
Upvotes: 1
Views: 1504
Reputation: 1785
As the others have told you Outlook must be installed if you want to use Outlook.Application
.
However, from your comments I read that you want to open an Outlook instance on the client, not on your server. This is not possible using Outlook.Application
. As I see it you have two possibilities:
Upvotes: 0
Reputation: 6814
Are there any reasons other than the dependency on Outlook being installed
nonsense
1.1. when you run it on your box - it starts Outlook using your account with your permissions, when running on server under ASP.NET account - it may not open any account even Outlook will be installed there
1.2. how do you want to see a server application (Outlook) within an ASP.NET website, which works within a browser window?
1.3 sending an email message does not require Outlook. See How Can i Send Mail Through Exchange Server by using SMTP If message needs to be modified before being sent - create a webform.
licensing (I bet your organization has no server licence for MS Office)
Upvotes: 0
Reputation: 81262
Yes it absolutely has to be installed. Outlook != Exchange.
You're using Outlook to automate "Outlook the application" - How can you do that if it isn't installed?
Automating Exchange is another story.
Upvotes: 1