|
41 | 41 | public class MailjetServlet extends HttpServlet { |
42 | 42 | private static final String MAILJET_API_KEY = System.getenv("MAILJET_API_KEY"); |
43 | 43 | private static final String MAILJET_SECRET_KEY = System.getenv("MAILJET_SECRET_KEY"); |
44 | | - private MailjetClient client = |
45 | | - new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY, new ClientOptions("v3.1")); |
| 44 | + ClientOptions options = |
| 45 | + ClientOptions.builder().apiKey(MAILJET_API_KEY).apiSecretKey(MAILJET_SECRET_KEY).build(); |
| 46 | + MailjetClient client = new MailjetClient(options); |
46 | 47 |
|
47 | 48 | @Override |
48 | | - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, |
49 | | - ServletException { |
| 49 | + public void doPost(HttpServletRequest req, HttpServletResponse resp) |
| 50 | + throws IOException, ServletException { |
50 | 51 | String recipient = req.getParameter("to"); |
51 | 52 | String sender = req.getParameter("from"); |
52 | 53 |
|
53 | | - MailjetRequest email = new MailjetRequest(Emailv31.resource) |
54 | | - .property(Emailv31.MESSAGES, new JSONArray() |
55 | | - .put(new JSONObject() |
56 | | - .put(Emailv31.Message.FROM, new JSONObject() |
57 | | - .put("Email", sender) |
58 | | - .put("Name", "Mailjet Pilot")) |
59 | | - .put(Emailv31.Message.TO, new JSONArray() |
60 | | - .put(new JSONObject() |
61 | | - .put("Email", recipient))) |
62 | | - .put(Emailv31.Message.SUBJECT, "Your email flight plan!") |
63 | | - .put(Emailv31.Message.TEXTPART, |
64 | | - "Dear passenger, welcome to Mailjet! May the delivery force be with you!") |
65 | | - .put(Emailv31.Message.HTMLPART, |
66 | | - "<h3>Dear passenger, welcome to Mailjet!</h3><br />" |
67 | | - + "May the delivery force be with you!"))); |
| 54 | + MailjetRequest email = |
| 55 | + new MailjetRequest(Emailv31.resource) |
| 56 | + .property( |
| 57 | + Emailv31.MESSAGES, |
| 58 | + new JSONArray() |
| 59 | + .put( |
| 60 | + new JSONObject() |
| 61 | + .put( |
| 62 | + Emailv31.Message.FROM, |
| 63 | + new JSONObject().put("Email", sender).put("Name", "Mailjet Pilot")) |
| 64 | + .put( |
| 65 | + Emailv31.Message.TO, |
| 66 | + new JSONArray().put(new JSONObject().put("Email", recipient))) |
| 67 | + .put(Emailv31.Message.SUBJECT, "Your email flight plan!") |
| 68 | + .put( |
| 69 | + Emailv31.Message.TEXTPART, |
| 70 | + "Dear passenger, welcome to Mailjet!" |
| 71 | + + "May the delivery force be with you!") |
| 72 | + .put( |
| 73 | + Emailv31.Message.HTMLPART, |
| 74 | + "<h3>Dear passenger, welcome to Mailjet!</h3><br />" |
| 75 | + + "May the delivery force be with you!"))); |
68 | 76 |
|
69 | 77 | try { |
70 | 78 | // trigger the API call |
|
0 commit comments