Search in sources :

Example 1 with MailjetSocketTimeoutException

use of com.mailjet.client.errors.MailjetSocketTimeoutException 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 MailjetSocketTimeoutException

use of com.mailjet.client.errors.MailjetSocketTimeoutException 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)

Aggregations

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