Send Email with Form information

Discussion in 'Java' started by teser3@hotmail.com, Oct 24, 2007.

  1. Guest

    --------------------------------------------------------------------------------
    I have a Form with 10 fields on it and I need to send an email with
    all 10 field values.

    The form will pass the values to a Servlet which will call a JavaBean
    class that will get the values and the email (JavaMail located in an
    email helper class) part will be called in the Servelt to send the
    JavaBean values. I assume I will also have to use the getMetaData
    method to get the field names?

    I dont have Struts or Sprint on my Tomcat 4.1.27 container.

    Is this the right direction where the Email output will be similiar to
    this:
    First Name: Joe
    Last Name: Smith
    City: Dallas
    State: Texas
    .....
     
    , Oct 24, 2007
    #1
    1. Advertising

  2. Roedy Green Guest

    On Tue, 23 Oct 2007 19:38:03 -0700, ""
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I have a Form with 10 fields on it and I need to send an email with
    >all 10 field values.


    I think you will have better luck putting the URL of a form in your
    email. That way you don't need to depend on the email program to
    render it and send the data, something I suspect most email programs
    would be reluctant to do.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Oct 24, 2007
    #2
    1. Advertising

  3. Daniel Pitts Guest

    Roedy Green wrote:
    > On Tue, 23 Oct 2007 19:38:03 -0700, ""
    > <> wrote, quoted or indirectly quoted someone who
    > said :
    >
    >> I have a Form with 10 fields on it and I need to send an email with
    >> all 10 field values.

    >
    > I think you will have better luck putting the URL of a form in your
    > email. That way you don't need to depend on the email program to
    > render it and send the data, something I suspect most email programs
    > would be reluctant to do.

    Either you or I misinterpreted what the OP wanted. I understood him
    wanting to have a web page with a form, that when he submitted it, an
    e-mail was generated from the values in the form.

    I didn't reply earlier, because I didn't feel like explaining the
    processes of form submission, and how to retrieve the query args from
    the request object, and then also connect to the JavaMail API to send
    e-mail.

    Hopefully, they can look into the JavaMail API themselves, and figure
    out what they want to do.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Oct 24, 2007
    #3
  4. On Oct 23, 7:38 pm, "" <> wrote:
    > --------------------------------------------------------------------------------
    > I have a Form with 10 fields on it and I need to send an email with
    > all 10 field values.
    >
    > The form will pass the values to a Servlet which will call a JavaBean
    > class that will get the values and the email (JavaMail located in an
    > email helper class) part will be called in the Servelt to send the
    > JavaBean values. I assume I will also have to use the getMetaData
    > method to get the field names?
    >
    > I dont have Struts or Sprint on my Tomcat 4.1.27 container.
    >
    > Is this the right direction where the Email output will be similiar to
    > this:
    > First Name: Joe
    > Last Name: Smith
    > City: Dallas
    > State: Texas
    > ....


    You would not need to use reflection to get the field names (not sure
    where the getMetaData API is coming from). In the servlet, you can
    parse the request parameters by calling getParameterMap() on the
    request. This will give you a map with key as the parameter name (the
    name that you give in the form as <input type="text"
    name="somename">), and the value is a String[]. Unless you have
    checkboxes in the form, you should only worry about [0]. You can then
    construct the email text by using parameter name and the value(s).

    -cheers,
    Manish
     
    Manish Pandit, Oct 24, 2007
    #4
  5. Guest

    Thanks, I am sending form info to people using JavaMail API.

    I wanted to use getParameterMap() and Enumeration but it seems to
    randomly
    place the values in micleaneous order:

    First Name: Joe
    Last Name: Smith
    City: Dallas
    State: Texas

    ends up looking like this sometimes:
    City: Dallas
    First Name: Joe
    State: Texas
    Last Name: Smith
     
    , Oct 25, 2007
    #5
  6. Roedy Green Guest

    On Wed, 24 Oct 2007 09:22:46 -0700, Daniel Pitts
    <> wrote, quoted or indirectly
    quoted someone who said :

    >Either you or I misinterpreted what the OP wanted. I understood him
    >wanting to have a web page with a form, that when he submitted it, an
    >e-mail was generated from the values in the form.


    I thought he wanted to send somebody an email with an embedded form.
    The user would enter data and it would be sent to a server.

    For email generated from values in a form, see
    http://mindprod.com/jgloss/javamail.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Oct 25, 2007
    #6
  7. Daniel Pitts Guest

    wrote:
    > Thanks, I am sending form info to people using JavaMail API.
    >
    > I wanted to use getParameterMap() and Enumeration but it seems to
    > randomly
    > place the values in micleaneous order:
    >
    > First Name: Joe
    > Last Name: Smith
    > City: Dallas
    > State: Texas
    >
    > ends up looking like this sometimes:
    > City: Dallas
    > First Name: Joe
    > State: Texas
    > Last Name: Smith
    >

    Form submission doesn't guaranty order of form elements. Neither does
    the Map interface. If you know before hand what the value are, then you
    can do something like this:

    private static final List<String> keys = Arrays.asList("First Name",
    "Last Name", "City", "State");

    public void printValues(Map<String, String> map) {
    for (String key: keys) {
    System.out.println(key + ": " + map.get(key));
    }
    }

    HTH.
    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Oct 25, 2007
    #7
  8. Lew Guest

    wrote:
    >> Thanks, I am sending form info to people using JavaMail API.
    >>
    >> I wanted to use getParameterMap() and Enumeration but it seems to
    >> randomly
    >> place the values in micleaneous order:


    How are you getting an Enumeration? There is no method in java.util.Map to
    return an Enumeration.

    --
    Lew
     
    Lew, Oct 25, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter
    Replies:
    0
    Views:
    3,374
    Peter
    Jul 1, 2003
  2. Eric Layman
    Replies:
    3
    Views:
    572
    sloan
    May 10, 2007
  3. Replies:
    2
    Views:
    410
    Tintin
    Jan 5, 2007
  4. Replies:
    1
    Views:
    701
    Randell D.
    Mar 17, 2005
  5. Replies:
    13
    Views:
    492
    Randy Webb
    May 14, 2006
Loading...

Share This Page