use of com.mailjet.client.MailjetRequest in project java-docs-samples by GoogleCloudPlatform.
the class MailjetServlet method doPost.
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
String recipient = req.getParameter("to");
String sender = req.getParameter("from");
MailjetRequest email = new MailjetRequest(Emailv31.resource).property(Emailv31.MESSAGES, new JSONArray().put(new JSONObject().put(Emailv31.Message.FROM, new JSONObject().put("Email", sender).put("Name", "pandora")).put(Emailv31.Message.TO, new JSONArray().put(new JSONObject().put("Email", recipient))).put(Emailv31.Message.SUBJECT, "Your email flight plan!").put(Emailv31.Message.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!").put(Emailv31.Message.HTMLPART, "<h3>Dear passenger, welcome to Mailjet!</h3><br /> " + "May the delivery force be with you!")));
try {
// trigger the API call
MailjetResponse response = client.post(email);
// Read the response data and status
resp.getWriter().print(response.getStatus());
resp.getWriter().print(response.getData());
} catch (MailjetException e) {
throw new ServletException("Mailjet Exception", e);
} catch (MailjetSocketTimeoutException e) {
throw new ServletException("Mailjet socket timed out", e);
}
}
use of com.mailjet.client.MailjetRequest in project java-docs-samples by GoogleCloudPlatform.
the class MailjetServlet method doPost.
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
String recipient = req.getParameter("to");
String sender = req.getParameter("from");
MailjetRequest email = new MailjetRequest(Emailv31.resource).property(Emailv31.MESSAGES, new JSONArray().put(new JSONObject().put(Emailv31.Message.FROM, new JSONObject().put("Email", sender).put("Name", "Mailjet Pilot")).put(Emailv31.Message.TO, new JSONArray().put(new JSONObject().put("Email", recipient))).put(Emailv31.Message.SUBJECT, "Your email flight plan!").put(Emailv31.Message.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!").put(Emailv31.Message.HTMLPART, "<h3>Dear passenger, welcome to Mailjet!</h3><br />" + "May the delivery force be with you!")));
try {
// trigger the API call
MailjetResponse response = client.post(email);
// Read the response data and status
resp.getWriter().print(response.getStatus());
resp.getWriter().print(response.getData());
} catch (MailjetException e) {
throw new ServletException("Mailjet Exception", e);
} catch (MailjetSocketTimeoutException e) {
throw new ServletException("Mailjet socket timed out", e);
}
}
use of com.mailjet.client.MailjetRequest in project teammates by TEAMMATES.
the class MailjetService method parseToEmail.
/**
* {@inheritDoc}
*/
@Override
public MailjetRequest parseToEmail(EmailWrapper wrapper) {
MailjetRequest request = new MailjetRequest(Email.resource);
request.property(Email.FROMEMAIL, wrapper.getSenderEmail());
if (wrapper.getSenderName() != null && !wrapper.getSenderName().isEmpty()) {
request.property(Email.FROMNAME, wrapper.getSenderName());
}
request.property(Email.RECIPIENTS, new JSONArray().put(new JSONObject().put("Email", wrapper.getRecipient())));
if (wrapper.getBcc() != null && !wrapper.getBcc().isEmpty()) {
request.append(Email.RECIPIENTS, new JSONObject().put("Email", wrapper.getBcc()));
}
request.property(Email.HEADERS, new JSONObject().put("Reply-To", wrapper.getReplyTo()));
request.property(Email.SUBJECT, wrapper.getSubject());
request.property(Email.HTMLPART, wrapper.getContent());
request.property(Email.TEXTPART, Jsoup.parse(wrapper.getContent()).text());
return request;
}
use of com.mailjet.client.MailjetRequest in project java-docs-samples by GoogleCloudPlatform.
the class MailjetSender method sendMailjet.
public MailjetResponse sendMailjet(String recipient, String sender, MailjetClient client) throws MailjetException, MailjetSocketTimeoutException {
MailjetRequest email = new MailjetRequest(Emailv31.resource).property(Emailv31.MESSAGES, new JSONArray().put(new JSONObject().put(Emailv31.Message.FROM, new JSONObject().put("Email", sender).put("Name", "pandora")).put(Emailv31.Message.TO, new JSONArray().put(new JSONObject().put("Email", recipient))).put(Emailv31.Message.SUBJECT, "Your email flight plan!").put(Emailv31.Message.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!").put(Emailv31.Message.HTMLPART, "<h3>Dear passenger, welcome to Mailjet!</h3>" + "<br />May the delivery force be with you!")));
try {
// trigger the API call
MailjetResponse response = client.post(email);
// Read the response data and status
System.out.println(response.getStatus());
System.out.println(response.getData());
return response;
} catch (MailjetException e) {
System.out.println("Mailjet Exception: " + e);
return null;
}
}
use of com.mailjet.client.MailjetRequest in project teammates by TEAMMATES.
the class EmailSenderTest method testConvertToMailjet.
@Test
public void testConvertToMailjet() {
EmailWrapper wrapper = getTypicalEmailWrapper();
MailjetRequest request = new MailjetService().parseToEmail(wrapper);
JSONObject email = new JSONObject(request.getBody());
assertEquals(wrapper.getSenderEmail(), email.get(Email.FROMEMAIL));
assertEquals(wrapper.getSenderName(), email.get(Email.FROMNAME));
assertEquals(wrapper.getRecipient(), ((JSONArray) email.get(Email.RECIPIENTS)).getJSONObject(0).get("Email"));
assertEquals(wrapper.getBcc(), ((JSONArray) email.get(Email.RECIPIENTS)).getJSONObject(1).get("Email"));
assertEquals(wrapper.getReplyTo(), ((JSONObject) email.get(Email.HEADERS)).getString("Reply-To"));
assertEquals(wrapper.getSubject(), email.get(Email.SUBJECT));
assertEquals(wrapper.getContent(), email.get(Email.HTMLPART));
}
Aggregations