Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting HTML Data in Java Program
    primarykey
    data
    text
    <p>I am trying to send Email from a Java program that I found here http://stackoverflow.com/questions/73580/how-do-i-send-an-smtp-message-from-java , This code works fine(with the hardcoded information), but I want to send the information from an HTML page that I created, It has From, To, Subject,Text inputs but I dont know how to send the values of these inputs from HTML page to this Java program.. Any help will be appreciated. Thanks</p> <p>Here is my Form</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Send Email&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 align="center"&gt;Email Sending Client&lt;/h1&gt; &lt;/tr&gt;&lt;/td&gt; &lt;table width=30% align="center"&gt; &lt;form id=myform method="get" action="" onSubmit="return validate();"&gt; &lt;br&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;From:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" name="email" id="email"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;To:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" name="to" id="to"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Subject:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" name="sub" id="sub"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Message:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;p&gt;&lt;textarea name="textarea" cols="16" rows="6"&gt;&lt;/textarea&gt;&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;br&gt; &lt;input type=submit value="Send" align="center"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/form&gt; &lt;/html&gt; </code></pre> <p>Code for Servlet</p> <pre><code>import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.net.InetAddress; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.mail.internet.*; import com.sun.mail.smtp.*; public class sendemail extends HttpServlet { public static void main(String args[]) throws Exception ,ServletException, IOException{ HttpServletRequest request=null; HttpServletResponse response=null; // Set response content type response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Using GET Method to Read Form Data"; String email= request.getParameter("email"); String to= request.getParameter("to"); String sub= request.getParameter("sub"); String smtp= request.getParameter("smtp"); String mess= request.getParameter("mess"); Properties props = System.getProperties(); props.put("mail.smtps.host","smtp.gmail.com"); props.put("mail.smtps.auth","true"); Session session = Session.getInstance(props, null); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(email));; msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); msg.setSubject(sub); msg.setText(mess); //msg.setHeader("X-Mailer", "Tov Are's program"); msg.setSentDate(new Date()); SMTPTransport t = (SMTPTransport)session.getTransport("smtp"); t.connect(smtp, "mymail@gmail.com", "mypassword"); t.sendMessage(msg, msg.getAllRecipients()); System.out.println("Response: " + t.getLastServerResponse()); t.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload