locked
Use C#.net to automatically copy and paste region of web page into outlook form RRS feed

  • Question

  • User-718146471 posted

    Well, I have been struggling with this whole opening an HTML email body inside an outlook email form but it would appear the text comes up as raw un-encoded HTML.  I'm looking for some way to instruct Outlook to render the body as HTML.  Here is my HTML email output section of the code:

            protected void btnSubmit_Click(object sender, EventArgs e)
            {
                try
                {
                    Outlook.Application oApp = new Outlook.Application();
                    Outlook._MailItem oMail = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                    oMail.To = string.Empty;
                    oMail.Subject = "Security Evaluation: " + txtAppName.Text.ToString();
                    oMail.HTMLBody = "Hello, we have audited the application titled " + txtAppName.Text.ToString() + ". 
    Please reply to us with your comments/fixes.<br /><br />" + Label1.Text.ToString() + "<br /><br />
    Please let us know if you have any questions.<br /><br /><br /> Thank you."; oMail.Display(true); btnSubmit.Visible = false; } catch (Exception ex) { Response.Write("Uh oh, something went wrong. Error: " + ex.ToString()); } }

    This code works great if I am on my local machine but it does not open the form on the client if deployed to production. I had considered doing a copy/paste into the body of the email form and that would be super, IF c#.net could paste it automatically after the outlook form opens.

    Tuesday, October 13, 2015 7:59 AM

Answers

  • User753101303 posted

    Hi,

    it does not open the form on the client if deployed to production

    It will never work. Keep in mind that this code runs on the web server so it appeared to be ok on your own machine as the server and the client are the same machine. It will never work in production as it runs on a real web server (so at best it would open Outlook on the web server).

    You could try: https://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx  (a "mailto" Href link)

    Sending maybe a .eml file could also perhaps work (the user would choose "Open" and it would open with the default app for .eml files).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 13, 2015 9:14 AM

All replies

  • User753101303 posted

    Hi,

    it does not open the form on the client if deployed to production

    It will never work. Keep in mind that this code runs on the web server so it appeared to be ok on your own machine as the server and the client are the same machine. It will never work in production as it runs on a real web server (so at best it would open Outlook on the web server).

    You could try: https://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx  (a "mailto" Href link)

    Sending maybe a .eml file could also perhaps work (the user would choose "Open" and it would open with the default app for .eml files).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 13, 2015 9:14 AM
  • User-718146471 posted

    Hm, responsing an .eml file from the server?  Now that could work.  The user base would know to expect that since I would be training them.  I'll look at the link you included to see what that has.  If you have code the will response a streamed .eml file to the client that opens in their mail client, that would be perfect.

    Tuesday, October 13, 2015 9:27 AM
  • User-718146471 posted

    Patrice, can you help me figure this out please? I have another thread related to creating an EML file which contains the contents of the formatted email. Can you take a look?

    https://forums.asp.net/p/2070965/5986828.aspx?Re+How+to+stream+outputted+file+to+client+as+response

    Monday, November 2, 2015 11:11 AM