use of com.mailjet.client.MailjetResponse 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.MailjetResponse 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.MailjetResponse 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.MailjetResponse in project teammates by TEAMMATES.
the class MailjetService method sendEmailWithService.
@Override
protected void sendEmailWithService(EmailWrapper wrapper) throws MailjetException, MailjetSocketTimeoutException {
MailjetRequest email = parseToEmail(wrapper);
MailjetClient mailjet = new MailjetClient(Config.MAILJET_APIKEY, Config.MAILJET_SECRETKEY);
MailjetResponse response = mailjet.post(email);
if (isNotSuccessStatus(response.getStatus())) {
log.severe("Email failed to send: " + response.getData().toString());
}
}
Aggregations