Skip to content

Instantly share code, notes, and snippets.

@eduardocs25
Forked from fizerkhan/contact-form-servlet
Last active August 29, 2015 14:07
Show Gist options
  • Save eduardocs25/53809e2852b53dfb5d8b to your computer and use it in GitHub Desktop.
Save eduardocs25/53809e2852b53dfb5d8b to your computer and use it in GitHub Desktop.
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("[email protected]",
"Acme Support Team"));
msg.setReplyTo(InternetAddress.parse("[email protected]"));
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);
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 <[email protected]>",
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 <[email protected]>",
subject="Got a message from customer")
message.to = '[email protected]'
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