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", "[email protected]");
formData.add("to", "[email protected]");
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
Regardless of your business case, Mailgun Email API empowers senders like you to build with the most powerful and reliable email service provider in the industry.
Free Email API For Easy Sending. Send, receive, and track emails with Mailgun's free email API.
TextMagic, also a Mailgun customer, allows you to send notifications, alerts, reminders, confirmations and SMS marketing campaign messages to your customers, staff members and suppliers. On average, TextMagic customers are sending over 2.5M text messages around the world each month.
I'm developing a Java mail library to easily send email messages using Mailgun. It may fit your needs.
https://github.com/sargue/mailgun
It allows you to send messages like this:
MailBuilder.using(configuration)
.to("[email protected]")
.subject("This is the subject")
.text("Hello world!")
.build()
.send();
Even file attachments are easy:
MailBuilder.using(configuration)
.to("[email protected]")
.subject("This message has an text attachment")
.text("Please find attached a file.")
.multipart()
.attachment(new File("/path/to/image.jpg"))
.build()
.send();
There is also support for asynchronous message sending and a HTML mail helper. It is a young project, feedback is very welcome.
You need the following dependencies:
You can download the JARs from mvnrepository and add them to your classpath.
Use the following dependencies if you should switch to Maven:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.19</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With