Search in sources :

Example 1 with MailjetResponse

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) JSONObject(org.json.JSONObject) MailjetResponse(com.mailjet.client.MailjetResponse) MailjetRequest(com.mailjet.client.MailjetRequest) MailjetSocketTimeoutException(com.mailjet.client.errors.MailjetSocketTimeoutException) JSONArray(org.json.JSONArray) MailjetException(com.mailjet.client.errors.MailjetException)

Example 2 with MailjetResponse

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) JSONObject(org.json.JSONObject) MailjetResponse(com.mailjet.client.MailjetResponse) MailjetRequest(com.mailjet.client.MailjetRequest) MailjetSocketTimeoutException(com.mailjet.client.errors.MailjetSocketTimeoutException) JSONArray(org.json.JSONArray) MailjetException(com.mailjet.client.errors.MailjetException)

Example 3 with MailjetResponse

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;
    }
}
Also used : JSONObject(org.json.JSONObject) MailjetResponse(com.mailjet.client.MailjetResponse) MailjetRequest(com.mailjet.client.MailjetRequest) JSONArray(org.json.JSONArray) MailjetException(com.mailjet.client.errors.MailjetException)

Example 4 with MailjetResponse

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());
    }
}
Also used : MailjetClient(com.mailjet.client.MailjetClient) MailjetResponse(com.mailjet.client.MailjetResponse) MailjetRequest(com.mailjet.client.MailjetRequest)

Aggregations

MailjetRequest (com.mailjet.client.MailjetRequest)4 MailjetResponse (com.mailjet.client.MailjetResponse)4 MailjetException (com.mailjet.client.errors.MailjetException)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 MailjetSocketTimeoutException (com.mailjet.client.errors.MailjetSocketTimeoutException)2 ServletException (javax.servlet.ServletException)2 MailjetClient (com.mailjet.client.MailjetClient)1