-
-
Save fizerkhan/4238893 to your computer and use it in GitHub Desktop.
Contact Form in Google App Engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>A form</title> | |
| </head> | |
| <body> | |
| <form action="feedback" method="post"> | |
| <!-- Simple text field --> | |
| <label for="name">Name </label> | |
| <input type="text" name="name"/> | |
| <br/> | |
| <!-- Email --> | |
| <label for="email">Email </label> | |
| <input type="email" name="email"/> | |
| <br/> | |
| <!-- Textarea --> | |
| <label for="description">Description </label> | |
| <textarea name="description" cols="50" rows="5">Type your comment here</textarea> | |
| <br/> | |
| <input type="submit" name="submit" value="Send Request"/> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package de.vogella.gae.feedback; | |
| import java.io.IOException; | |
| import java.util.Properties; | |
| import javax.mail.Message; | |
| import javax.mail.Session; | |
| import javax.mail.Transport; | |
| import javax.mail.internet.InternetAddress; | |
| import javax.mail.internet.MimeMessage; | |
| import javax.servlet.ServletException; | |
| import javax.servlet.http.HttpServlet; | |
| import javax.servlet.http.HttpServletRequest; | |
| import javax.servlet.http.HttpServletResponse; | |
| @SuppressWarnings("serial") | |
| public class FeedbackServlet extends HttpServlet { | |
| @Override | |
| protected void doPost(HttpServletRequest req, HttpServletResponse resp) | |
| throws ServletException, IOException { | |
| String name = req.getParameter("name"); | |
| String description = req.getParameter("description"); | |
| String email = req.getParameter("email"); | |
| Properties props = new Properties(); | |
| Session session = Session.getDefaultInstance(props, null); | |
| String msgBody = name + "\n" + description + "\n" + email; | |
| try { | |
| Message msg = new MimeMessage(session); | |
| msg.setFrom(new InternetAddress("your_admin@googlemail.com", | |
| "Your admin")); | |
| msg.addRecipient(Message.RecipientType.TO, new InternetAddress( | |
| "your_email@example.com", "Your name")); | |
| msg.setSubject("Feedback"); | |
| msg.setText(msgBody); | |
| Transport.send(msg); | |
| } catch (Exception e) { | |
| resp.setContentType("text/plain"); | |
| resp.getWriter().println("Something went wrong. Please try again."); | |
| throw new RuntimeException(e); | |
| } | |
| resp.setContentType("text/plain"); | |
| resp.getWriter().println( | |
| "Thank you for your feedback. An Email has been send out."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment