I am trying to take advantage of Mailgun's Transactional Email Service via their RESTful API, but I can not make it work. I am able to send emails via SMTP but i prefer to use their API.
Their documentation provides me with the following code:
public static ClientResponse SendSimpleMessage() {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api",
"key-*****"));
WebResource webResource =
client.resource("https://api.mailgun.net/v2/DOMAIN" +
"/messages");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", "Excited User <mailgun@DOMAIN>");
formData.add("to", "bar@example.com");
formData.add("to", "bar@example.com");
formData.add("subject", "Hello");
formData.add("text", "Testing some Mailgun awesomness!");
return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
post(ClientResponse.class, formData);
}
Obviously I need some kind of REST client to take advantage of this code, but I have not been able to find anything online that works for me. Can someone please explain to me step by step how I make this work. I am using Eclipse, JAVA EE, No Maven