title: Getting users email address in java servlet
body: <p>I have a contact us form created in jsp using this code. </p>
  
  <pre><code>       &lt;form action="ContactServlet" method="post"&gt;
              &lt;p&gt;Your email address: &lt;input name="email"&gt;&lt;/p&gt;
              &lt;p&gt;Mail subject: &lt;input name="subject"&gt;&lt;/p&gt;
              &lt;p&gt;Mail message: &lt;textarea name="message"&gt;&lt;/textarea&gt;&lt;/p&gt;
              &lt;p&gt;&lt;input type="submit"&gt;&lt;/p&gt;
              &lt;label name="lblMessageSent"&gt;&lt;/label&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>I configured my servlet to use gmail and also hard coded the username and password for the email to be sent from. The problem is I want the users email to appear as sent from or if its any easier I would show the users email somehow in the email received. </p>
  
  <pre><code>        String from = request.getParameter("email");
          message.setFrom(new InternetAddress(from));
  
          message.setRecipients(Message.RecipientType.TO,
                  InternetAddress.parse("adonisokpidi@gmail.com"));
  
          String subject = request.getParameter("subject");
          message.setSubject(subject);
  
          String messageContent = request.getParameter("message");
          message.setText(messageContent);
  
          Transport.send(message);
  
          response.sendRedirect("contact.jsp");
  </code></pre>
  
  <p>As you can see, the email's from address should be the one from the HTML form's <code>email</code> field, but actually all mails are send with the hard-coded username and password. </p>
  
  <p><em>Question</em> #1: How do I make this work?</p>
  
  <p><em>Question</em> #2: How do I make the form display the label with the content message sent in the contact.jsp after the message has been sent. </p>
  
  <p>Thanks</p>