Submit Form to email body as plain text? - InfoPath Dev
in

InfoPath Dev

Submit Form to email body as plain text?

Last post 01-17-2008 09:15 AM by ScottD. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts: Previous Next
  • 10-11-2005 12:53 AM

    • Antz79
    • Not Ranked
    • Joined on 10-11-2005
    • Posts 3

    Submit Form to email body as plain text?

    Hi,

    Is it possible to submit form as an email, to the body as text.. not as an attachement. I use code like this :

    function mailMessage(to,subject,cc,body,bcc)
    { try
    { var myOlApp = new ActiveXObject("Outlook.Application");
    newMail = myOlApp.CreateItem(0);
    newMail.To = to;
    newMail.Subject = subject;
    newMail.CC = cc;
    newMail.BCC = bcc;
    newMail.Body = body;
    newMail.Send();
    }
    catch(ex){
    XDocument.UI.Alert(ex.description);
    }
    }
    CTRL81_7::OnClick(eventObj)
    {
    mailMessage ("[email protected]","Hallå","",XDocument.DOM.xml,"");
    }

    I get the form as text in the body, BUT it doesnt lock very nice...
    Is it possible to make it look better? like this:

    Name : Andres
    Age: 25
    Town: Gothenburg

    Now it loocks like this : Name='Andreas'Age='25'Town='Gothenburg'...

    Thanks for answer !

    //Andreas
  • 10-11-2005 09:51 AM In reply to

    Re: Submit Form to email body as plain text?

    You will need to build the body content yourself in code. That may not sound very pleasant if you have a lot of fields, but that is what you will need to do.

    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 10-11-2005 11:28 PM In reply to

    • Antz79
    • Not Ranked
    • Joined on 10-11-2005
    • Posts 3

    Re: Submit Form to email body as plain text?

    Ok, Could you give me an example how that is done ? If you use like two fields... I´m new to this, so help would be very thanksful!.

    BR
    Andreas
  • 10-12-2005 06:54 AM In reply to

    Re: Submit Form to email body as plain text?

    You'll need to use formatting and escape characters. Depending on what language you're using you'll need to look up with escape character for "newline." If you're using JScript (which it looks like you are) take a look at this for a complete reference:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsconStringData.asp

    As an example, with your data and the three fields you would have something like this:

    var subject = "Name : \'" + XDocument.DOM.selectSingleNode( "\\my:name_field" ).text + "\'\n"
    + "Age : \'" + XDocument.DOM.selectSingleNode( "\\my:age_field" ).text + "\'\n"
    + "Town : \'" + XDocument.DOM.selectSingleNode( "\\my:town_field" ).text + "\'\n\n"
    + "To unsubscribe to this mailing list, go to www.aol.com";


    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-04-2005 05:46 AM In reply to

    Re: Submit Form to email body as plain text?


    This is driving me nuts!

    I am trying to do the simple bit as in just get a button to send the body in the email (although I would like to format it also, hence why I chose this post).

    However I can;t even get the first bit right and have tried inserting about 4 lots of code from different posts on the subject and none of them work!

    When I first pasted this one in it said i was missing a ';' on the CTRL81_7::OnClick(eventObj) line above so I added one but it's now saying I need one elsewhere:

    This is an exact copy of what my code page looks like - what am I doing wrong?

    /*
    * This file contains functions for data validation and form-level events.
    * Because the functions are referenced in the form definition (.xsf) file,
    * it is recommended that you do not modify the name of the function,
    * or the name and number of arguments.
    *
    */

    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-12-04T13:29:03"');
    //</namespacesDefinition>


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======

    function mailMessage(to,subject,cc,body,bcc)
    { try
    { var myOlApp = new ActiveXObject("Outlook.Application");
    newMail = myOlApp.CreateItem(0);
    newMail.To = to;
    newMail.Subject = subject;
    newMail.CC = cc;
    newMail.BCC = bcc;
    newMail.Body = body;
    newMail.Send();
    }
    catch(ex){
    XDocument.UI.Alert(ex.description);
    }
    }
    CTRL81_7::OnClick(eventObj);
    {
    mailMessage ("[email protected]","Hallå","",XDocument.DOM.xml,"");
    }



    // Write your code here
    }

    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function CTRL1_5::OnClick(eventObj)
    {
    // Write your code here
    }



    Help!
  • 12-05-2005 07:09 AM In reply to

    Re: Submit Form to email body as plain text?


    Well I have cheated slightly but I've come up with a really nice way of sending the form as the email body and in the exact same form as it is on Infopath.

    I found the email code on one of the Customized forms with Inpopath (the Assett tracking one). I just deleted everything and copied my form onto it and it works beautifally!

    The email result is a perfect copy of the form inside the email body.. theres probably a hitch somewhere that I haven;t found yet!
  • 12-05-2005 07:15 AM In reply to

    Re: Submit Form to email body as plain text?


    Sorry, the sample form is Issue Tracking, not Asset Tracking.
  • 12-05-2005 08:50 PM In reply to

    Re: Submit Form to email body as plain text?

    Hi Julie-Mids,
    Superb sleuthing job! I remember working on the Issue Tracking form over three years ago... :) Glad it's still useful!

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 02-07-2007 09:14 AM In reply to

    Re: Submit Form to email body as plain text?

    Building on this topic, I have the following code for my Submit button (copied from the aformentiond form, thank you VERY MUCH!)

    function SendEmailBtn::OnClick(oEvent)
    {
    createEmail();
    }



    function createEmail()
    {
    var xmlContributors = XDocument.DOM.selectNodes("/iss:issue/iss:contributors/iss:contributor");
    var xmlContributor;
    var xmlTitle = XDocument.DOM.selectSingleNode("/iss:issue/iss:title");
    var rgRecipients = new Array();

    while (xmlContributor = xmlContributors.nextNode())
    rgRecipients.push(getNodeValue(xmlContributor.selectSingleNode("iss:emailAddressPrimary")));

    try
    {
    var oEnvelope = XDocument.View.Window.MailEnvelope;

    oEnvelope.To = rgRecipients.join(" ;");
    oEnvelope.Subject = getNodeValue(xmlTitle);
    oEnvelope.Visible = true;
    }
    catch (ex)
    {
    XDocument.UI.Alert(ex.description);
    }
    }

    I would like to add text for the "Introduction" and hardcode an additional email address or two for "To:" and "cc:".

    Can someone help this IP newbie/non-programmer?
  • 04-15-2007 03:18 PM In reply to

    • Susanna
    • Not Ranked
      Female
    • Joined on 03-09-2007
    • Australia
    • Posts 7

    Re: Submit Form to email body as plain text?

    Hi there,

    I seem to have a 'same same but different' issue...  Please read the thread here: http://infopathdev.com/forums/thread/1947.aspx and maybe you can help me.  I would really appreciate it.

    /Susanna

    Getting there...
  • 08-09-2007 06:15 AM In reply to

    Re: Submit Form to email body as plain text?

    Matt, I see how this example for formatting text works, however I am a bit new to XML.  if you are using selectNodes() instead of selectSingleNode to select all values in a repeating table, I would like to know if there is any way to grab entire rows.  For example if you had a table with three columns, clearly the xml knows which 3 values are the first record, second record etc.  Can you help me identify how to grab whole rows (records) in a repeating table?  I can work on the formatting myself, its grabbing multiple values by their row that is stumping.  I am sending this in an email (got that part figured out).  I drew a example repeating table below.  My goal is to print into the email  foo, bar, hat.  The real situation is that I have a repeating table with "comments" each one has a number, comment text, and a timestamp, I want to get them into the email just like they appear in the repeating table.  Any ideas?  Thanks for anything you can provide.

    -Justin 

          A   B   C
    1     f    o   o

    2     b   a   r

    3     h   a   t

    -Justin Devine
    Consultant
    Filed under:
  • 12-24-2007 03:10 AM In reply to

    Re: Submit Form to email body as plain text?

    Julie

    I can't quite figure what you mean by delete everything and copy a form on top.

    Are you refering to deleting the code or the design page?

    Thanks

    Bob

    Cheers
    Bob
  • 12-24-2007 10:19 AM In reply to

    Re: Submit Form to email body as plain text?

    Ok - I got it sorted, just working on the cc: field now

    Excellent!

    Cheers
    Bob
  • 12-26-2007 08:42 AM In reply to

    Re: Submit Form to email body as plain text?

    Patrick

    I've taken Julie's solution (I copied the button to my absence request form and played around with it until it worked) and I can get the "To:" field populated. Now I need to figure out the "CC" field, I need to add two email contacts - as in the standard Absence request form, for "contacts while away"

    This is what I have so far -


    function createEmail()
    {
     var xmlmanager = XDocument.DOM.selectNodes("/ar:absenceRequest/ar:manager/ar:name");
     var xmlname;
     var xmlTitle = XDocument.DOM.selectSingleNode("/ar:absenceRequest/ar:title");
     var rgRecipients = new Array();
     while (xmlname = xmlmanager.nextNode())
      rgRecipients.push(getNodeValue(xmlname.selectSingleNode("ar:singleName")));

     try
      {
      var oEnvelope = XDocument.View.Window.MailEnvelope;
     
      oEnvelope.To = rgRecipients.join("; ");
      oEnvelope.Subject = getNodeValue(xmlTitle);
      oEnvelope.Visible = true;
      }
     catch (ex)
      {
      XDocument.UI.Alert(ex.description);
      }
    }

    If anybody can tell me how to add the "CC:" , that would be a great help?

    Cheers

    Bob

    Cheers
    Bob
  • 12-27-2007 01:35 PM In reply to

    Re: Submit Form to email body as plain text?

    Hi Bob,

    Judging from the following blog, it looks like it's just oEnvelope.CC. 

    http://blogs.msdn.com/infopath/archive/2004/08/17/216172.aspx

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 2 (17 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.