Last active
May 12, 2020 09:55
-
-
Save fizerkhan/fb251c06c168c294abe4 to your computer and use it in GitHub Desktop.
Google App Engine Servlet for Contact form
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
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); |
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
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() |
@duardocs25 Updated for python.
thanks a lot, But as you may receive the message in my email client? here I am only able to send a message of thanks
@eduardocs25 Updated.
you're awesome! Thanks a lot !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I do this in python ??? thanks a lot