Essential App Engine: Building High-Performance Java Apps with Google App Engine (Eiji Yamane's Library) by Adriaan de Jonge
Author:Adriaan de Jonge
Language: eng
Format: epub
Publisher: Addison-Wesley
Published: 2012-08-22T04:00:00+00:00
* * *
01 package com.appspot.mail;
02
03 import java.io.IOException;
04
05 import javax.servlet.ServletException;
06 import javax.servlet.http.HttpServlet;
07 import javax.servlet.http.HttpServletRequest;
08 import javax.servlet.http.HttpServletResponse;
09
10 import org.antlr.stringtemplate.StringTemplate;
11 import org.antlr.stringtemplate.StringTemplateGroup;
12
13 import com.google.appengine.api.mail.MailService;
14 import com.google.appengine.api.mail.MailServiceFactory;
15 import com.google.appengine.api.mail.MailService.Message;
16
17 /**
18 * Low-level alternative to SendConfirmationJMServlet.
19 */
20 public class SendConfirmationLLServlet extends HttpServlet {
21
22 private static final String SENDER =
23 "No Reply <[email protected]>";
24 private static final StringTemplateGroup templates =
25 new StringTemplateGroup("mail", "WEB-INF/templates/mail");
26
27 private static final long serialVersionUID = 818089810592369246L;
28
29 protected void doPost(HttpServletRequest request,
30 HttpServletResponse response)
31 throws ServletException, IOException {
32
33 String recipient = request.getParameter("recipient");
34 String thread = request.getParameter("thread");
35 String url = request.getParameter("url");
36 String message = request.getParameter("message");
37
38 String subject = createSubject(thread);
39 String body = createBody(url, thread);
40 String htmlBody = createHtmlBody(url, thread);
41 String attachment = createAttachment(message);
42
43 sendMail(recipient, subject, body, htmlBody, attachment);
44 }
45
46 private void sendMail(String recipient, String subject,
47 String body, String htmlBody, String attachment)
48 throws IOException {
49 MailService mailService = MailServiceFactory.getMailService();
50 Message mail = new Message(SENDER, recipient, subject, body);
51 mail.setHtmlBody(htmlBody);
52 mail.setAttachments(new MailService.Attachment("message.txt",
53 attachment.getBytes()));
54 mailService.send(mail);
55 }
56
57 private String createBody(String url, String thread) {
58 StringTemplate body =
59 templates.getInstanceOf("confirmation-body");
60 body.setAttribute("url", filter(url));
61 body.setAttribute("thread", filter(thread));
62 return body.toString();
63 }
64
65 private String createHtmlBody(String url, String thread) {
66 StringTemplate body =
67 templates.getInstanceOf("confirmation-html-body");
68 body.setAttribute("url", filter(url));
69 body.setAttribute("thread", filter(thread));
70 return body.toString();
71 }
72
73 private String createSubject(String thread) {
74 StringTemplate subject =
75 templates.getInstanceOf("confirmation-subject");
76 subject.setAttribute("thread", filter(thread));
77 return subject.toString();
78 }
79
80 private String createAttachment(String message) {
81 StringTemplate subject =
82 templates.getInstanceOf("confirmation-attachment");
83 subject.setAttribute("message", filter(message));
84 return subject.toString();
85 }
86
87 private String filter(String text) {
88 if (text == null)
89 return "";
90 return text.replaceAll("<?>?", "");
91 }
92 }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(21740)
Hello! Python by Anthony Briggs(20966)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(19452)
Dependency Injection in .NET by Mark Seemann(19014)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(18643)
Kotlin in Action by Dmitry Jemerov(18465)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(18228)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(17086)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(16953)
Grails in Action by Glen Smith Peter Ledbrook(16198)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(13869)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(11876)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(10678)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10592)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(9785)
Hit Refresh by Satya Nadella(9101)
The Kubernetes Operator Framework Book by Michael Dame(8534)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8358)
Robo-Advisor with Python by Aki Ranin(8303)