Click here to Skip to main content
16,021,294 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
Email an ASP.net-MVC web form (including data displayed in it) using Outlook client. Prefer java script. I have seen solutions that requires building controllers and then create a view to email. I am sure there will be simpler and easy way out than building a full controller itself. It is easy to print the form but, I have big challenge to send the same form using outlook client. It is ok, even if we could have it as HTML message or pdf attachment. Any help in this direction will be greatly appreciated, kindly excuse my language. Please feel free and let me know if, any point needs more explanation. Sincerely thanking for your time to read and help in advance.

What I have tried:

I have tried using controllers but I am thinking of an easier option to have a javascript run to handle the email along with the page at client side.
I tried the following but it seems to be only working with IE. Please suggest any improvements

<script>
       function openOutlook() {
           var email = 'xxxxxx@mail.com';
           var subject = 'Test Mail';
           var emailBody = document.getElementById("content").innerHTML;
           window.location = "mailto:" + email + "?subject=" + subject + "&body=" + emailBody;
       }
       function openOutlookwithFormattedContent() {

           var outlookAXO = new ActiveXObject("Outlook.Application");
           var nameSpace = outlookAXO.getNameSpace("MAPI");
           mailFolder = nameSpace.getDefaultFolder(6);
           mailItem = mailFolder.Items.add('IPM.Note.FormA');
           mailItem.Subject = "Test Mail";
           mailItem.To = "TestMail@gmail.com";
           mailItem.HTMLBody = document.getElementById("content1").innerHTML;
           mailItem.display(0);
       }

   </script>
Posted
Updated 28-Aug-17 10:00am
v3

1 solution

Simple there is no improvement. ActiveX is an outdated, dead technology that has not place in modern development. The security issues associated are more than enough reason not to use it along with the fact you found it only works in IE. Even then only older versions allow ActiveX controls by default.

It is not that hard or time consuming to create a method server side to send the email
 
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