locked
Need help getting formatted data into an Outlook Email from ASP page RRS feed

  • Question

  • User785066103 posted

    I'd like to "push" some formatted text to an outlook email from an ASP application.  My salesreps create quotes with multiple products, and I want the emails they send to look clean and consistently professional before they send them.  This is also a major timesaver since they do this all day long.

    I've got it mostly working with a few limitations.

    1) The first is that I can highlight and copy the text w/ a control, open a new outlook mail message and paste it manually, no problem. (it would be really nice to not have to highlight the text w/ the mouse, but I've found NO way to do this)

    2) the second button allows me to highlight the text, and pop open an Outlook email msg with the subject filled in, and the text pasted to the body, but I loose all of the formatting.

    q: is there any way to preseve the formatting when doing this?

    3) what I'd REALLY like to have is a button that ADDs new formatted, highlighted text to my newly createda and open email. That would be the ultimate :)

    I've also found no other way than TEXTAREA to accomplish this, and hiding that control w/ DIV stops it from working.  If it's not visibile, it doesn't seem to work.

    The 3 scenarios look like this right now.  As you can see, the one email that is auto-generated lost all it's formatting:

    creating emails from inventory app


    Here's the code I've got so far on my Inventory ASP application:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>

    <META name=GENERATOR content="MSHTML 8.00.6001.18783"></HEAD>
    <BODY>
    <SCRIPT language=JavaScript>
       var nameSpace = null;
       var mailFolder = null;
       var mailItem = null;
       var tempDoc = null;
       var outlookApp = null;
       var emailBody = null;

    function copyit(theField)
    {
        var selectedText = document.selection;
        if (selectedText.type == 'Text') {
            var newRange = selectedText.createRange();
            theField.focus();
            theField.value = newRange.text;
        } else {
            alert('Select some text in the page and then click that button');
        return;
        }
        newRange.execCommand("Copy");
    }
    function OpenOutlookDoc(whatform,theField)
       {
          try
          {
          outlookApp = new ActiveXObject("Outlook.Application");
          nameSpace = outlookApp.getNameSpace("MAPI");
          mailFolder = nameSpace.getDefaultFolder(6);
          mailItem = mailFolder.Items.add(whatform);
        //set subject of Outlook email message
          mailItem.Subject = 'Wine Selections from Provino Premium Wines';
     
     //set body of Outlook email message
        var selectedText = document.selection;
        if (selectedText.type == 'Text') {
            var newRange = selectedText.createRange();
            theField.focus();
            theField.value = newRange.text;
        newRange.execCommand("Copy");
            mailItem.Body = newRange.text;
        } else {
            alert('Select some text in the page and then click that button');
        return;
        }
    //    newRange.execCommand("Copy");

         
     //show final Outlook email on user's screen     
          mailItem.display(0);   

          }
          catch(e)
          {
          // act on any error that you get
          }
          }


    </SCRIPT>
    {BEGIN details_data}
    <P>
    <TABLE style="WIDTH: 98%" border=1 cellSpacing=0
    cellPadding=0>
      <TBODY>{BEGIN details_row}<STRONG>{$Description_value}</STRONG>&nbsp;&nbsp;<STRONG>{$Price_value}</STRONG><BR>{$LongDesc_value}
      {END details_row}<BR>&nbsp;
      <P></P></TBODY>{END details_data}</TABLE>
    <FORM name=it><INPUT onclick=copyit(this.form.select1) value="Copy Highlighted Text" type=button name=btnCopy>
    &nbsp;&nbsp;&nbsp; <FORM name="MailIt"><INPUT onclick="OpenOutlookDoc('IPM.Note.Service Centre',this.form.select1)" value="Email Highlighted Text" type=button name=btnEmail>
    <TEXTAREA rows=1 cols=1 name=select1></TEXTAREA> </FORM></P></BODY></HTML>


    Anyone care to enlighten me on some of this?  I'm amazed I've gotten this far in 48 hours of work....

    Jeff


    Monday, July 13, 2009 12:20 AM

All replies

  • User-1659704165 posted

    Hi,
    //Csharp code
    http://msdn.microsoft.com/en-us/library/aa289167(VS.71).aspx

    //Other Codes
    http://www.outlookcode.com/


    Chck the above Link...

    Monday, July 13, 2009 1:00 AM
  • User353179485 posted

    Hi , One solution is try and create a module to script your text to an EML document. This is basically an XML document containing your mail document [somewhat to html formal with <body>... etc] only issue is embedding pictures since in EML documents picture files are embedded in the same file unlike html docs with image paths.



    Monday, July 13, 2009 1:09 AM
  • User785066103 posted

    That's actually a great idea for a number of reasons!  However, I havnt found a way to open a .eml file w/ Outlook yet.  The problem is that .eml docs are opened by Outlook Express - I tried changing the type and then opening the file w/ Outlook 2007, but it just attaches the file to a new email message as a MIME doc.... 

    Jeff

    Monday, July 13, 2009 2:01 PM
  • User-1936035690 posted
    Hi Jeff,
    Outlook only opens .msg files that are stored in the Outlook format. .Eml files are actually RFC2822 formatted files, which Outlook can't read.

    Cheers!
    Dave
    Tuesday, July 14, 2009 2:27 PM