/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.managedvms.mailjet;

import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.resource.Email;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(name = "mailjet", value = "/send/email")
public class MailjetServlet extends HttpServlet {
  private static final String MAILJET_API_KEY = System.getenv("MAILJET_API_KEY");
  private static final String MAILJET_SECRET_KEY = System.getenv("MAILJET_SECRET_KEY");
  private MailjetClient client = new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY);

  @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(Email.resource)
        .property(Email.FROMEMAIL, sender)
        .property(Email.FROMNAME, "pandora")
        .property(Email.SUBJECT, "Your email flight plan!")
        .property(Email.TEXTPART,
            "Dear passenger, welcome to Mailjet! May the delivery force be with you!")
        .property(Email.HTMLPART,
            "<h3>Dear passenger, welcome to Mailjet!</h3><br/>May the delivery force be with you!")
        .property(Email.RECIPIENTS, new JSONArray().put(new JSONObject().put("Email", recipient)));

    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);
    }
  }
}

@@ -607,16 +607,43 @@
 e.%0A */%0A%0A
+// %5BSTART mailjet_imports%5D%0A
 package 
@@ -893,16 +893,41 @@
 e.Email;
+%0A// %5BEND mailjet_imports%5D
 %0A%0Aimport
@@ -1221,16 +1221,31 @@
 ponse;%0A%0A
+// %5BSTART app%5D%0A
 @Suppres
@@ -2758,8 +2758,33 @@
 %7D%0A  %7D%0A%7D%0A
+// %5BEND mailjet_imports%5D%0A

Update MailjetServlet.java