Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.resource.Email;
import com.mailjet.client.resource.Emailv31;
// [END mailjet_imports]

import org.json.JSONArray;
Expand All @@ -39,23 +40,26 @@
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);
private MailjetClient client = new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY, new ClientOptions("v3.1"));

@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)));
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.resource.Email;
import com.mailjet.client.resource.Emailv31;
// [END mailjet_imports]

import org.json.JSONArray;
Expand All @@ -34,23 +35,27 @@ public class MailjetSender{
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
final String mailjetApiKey = "YOUR-MAILJET-API-KEY";
final String mailjetSecretKey = "YOUR-MAILJET-SECRET-KEY";
MailjetClient client = new MailjetClient(mailjetApiKey, mailjetSecretKey);
MailjetClient client = new MailjetClient(mailjetApiKey, mailjetSecretKey, new ClientOptions("v3.1"));

MailjetSender sender = new MailjetSender();
sender.sendMailjet(args[0], args[1], client);
}

public MailjetResponse sendMailjet(String recipient, String sender, MailjetClient client)
throws MailjetException, MailjetSocketTimeoutException {
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)));
MailjetRequest email = new MailjetRequest(Emailv31.resource)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use tabs, but do use two spaces, not 4. If you could fix that, then I'll LGTM

.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.resource.Email;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.resource.Emailv31;
// [END mailjet_imports]

import org.json.JSONArray;
Expand All @@ -42,23 +43,26 @@
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);
private MailjetClient client = new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY, new ClientOptions("v3.1"));

@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)));
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
Expand Down