Reputation: 73
I use Asp.net WebForm I have a problem with Outlook Application. When user wants to submit a report/order from the Browser by email in Outlook it creates 2 emails instead of one. I literally don't understand what may be a problem.
Here is a part that is responsible for creating and sending email:
//Send email
try
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
MailAddress to = new MailAddress(email_primary);
MailAddress cc = new MailAddress(email_cc);
mailItem.To = to.ToString();
mailItem.CC = cc.ToString();
mailItem.Subject = "MB Accessories Order";
mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mailItem.Body = "Dear Colleagues, Please find below my MB Accessories & Collection enquiry for MBCME price (VAT included) and availability. FullName:" + Fullname_converted + " Items:" + joinedData + "";
mailItem.Display(false);
//mailItem.Send();
Response.Write("E-mail sent!");
}
catch (Exception eX)
{
throw new Exception("cDocument: Error occurred trying to Create an Outlook Email" + Environment.NewLine + eX.Message);
}
If you need more information, just let me know.
Upvotes: 1
Views: 67
Reputation: 66276
You cannot run that code on the server. Your options are
JS on the client side - has to be IE, and the site must be trusted to be able to create COM objects.
Create an EML (MIME) message on the server side and let the user download it - Outlook will be happy to open and display it. To make sure the message is in the unsent state, set X-Unsent
MIME header to 1.
Upvotes: 0
Reputation: 73
I solved this problem by implementing instead of html button instead of:
<button id="idbutton" runat="server" onserverclick="btn_submit_Click">Submit</button>
i used
<asp:Button runat="server" Text="Submit" OnClick="btn_submit_Click" />
and now it works fine
Upvotes: 1