-
-
Save wilfriedE/e359e8758ec4a16e1fe6 to your computer and use it in GitHub Desktop.
Google App Engine Servlet for Contact form
This file contains 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
String name = req.getParameter("name"); | |
String email = req.getParameter("email"); | |
String message = req.getParameter("message"); | |
// Create Mail message | |
Properties props = new Properties(); | |
Session session = Session.getDefaultInstance(props, null); | |
Message msg = new MimeMessage(session); | |
msg.setFrom(new InternetAddress("support@acme.com", | |
"Acme Support Team")); | |
msg.setReplyTo(InternetAddress.parse("support@acme.com")); | |
msg.addRecipient(Message.RecipientType.TO, new InternetAddress( | |
email, | |
name)); | |
msg.setSubject("Thanks for contacting us"); | |
// Set mail text and send it | |
msg.setText("We will update as soon as possible.\n Thanks\n -Acme Team"); | |
Transport.send(msg); |
This file contains 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
import webapp2 | |
from google.appengine.api import mail | |
class ContactHandler(webapp2.RequestHandler): | |
def post(self): | |
name = self.request.get("name") | |
to_addr = self.request.get("email") | |
content = self.request.get("content") | |
if not mail.is_email_valid(to_addr): | |
# Return an error message... | |
pass | |
# Send Thanks mail to customer | |
message = mail.EmailMessage(sender="Acme Support <support@acme.com>", | |
subject="Thanks for contacting us") | |
message.to = to_addr | |
message.body = """ | |
Hi There: | |
Thanks for contacting us. We will reply back as soon as we got this mail. | |
Please let us know if you have any questions. | |
The acme Team | |
""" | |
message.send() | |
# Send mail to me(admin) about customer message | |
message = mail.EmailMessage(sender="Acme Support <support@acme.com>", | |
subject="Got a message from customer") | |
message.to = 'me@acme.com' | |
message.body = """ | |
Hi Admin: | |
We got a message from %s - %s | |
Content: %s | |
The acme Team | |
""" % (name, to_addr, content) | |
message.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment