0

in my development machine I developed a method that work without problem. Its a simple button and when I clicked it open an outlook email with a email adress and some content But when I sent the code to the production enviroment... all users are getting an error on page_load of the page where the following method are set.

protected void btnSendEmail_Click(object sender, ImageClickEventArgs e)
{
    //...
    Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
    string name = someDataTable.Rows[0]["NAME"].ToString();
    string url = HttpContext.Current.Request.Url.AbsoluteUri;
    oMailItem.To = [email protected];
    oMailItem.Body = string.Format("hi {0}, \n \n [Insert the content mail here.] \n \n {1} ", name, url);
    oMailItem.Subject = "Some Title";
    oMailItem.Display(false);
}
1
  • What's the error, my crystal ball is on the blink at the moment.
    – OTTA
    Commented Jan 7, 2014 at 14:32

1 Answer 1

1

The Microsoft Office Interop assemblies would open Outlook on the server (assuming Outlook is installed on the server), not on the client. Is that your intention?

The Microsoft Office Interop assemblies are not supported on the server side. See KB Article.

I suggest you switch to some other technology. If you're just trying to have the server send an email, try taking at look at the System.Net.Mail namespace. See How To Send An Email With C#.

If your intention is to launch an Outlook new email window on the client side, it's easy to accomplish that with a simple HTML anchor link. See Sending HTML in mailto anchor tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.