Java REST Mailgun

I am trying to use MailGun Transactional Email Service through my RESTful API, but I cannot get it to work. I can send messages through SMTP, but I prefer to use their API.

Their documentation contains 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 use this code, but I could not find anything on the Internet that works for me. Can someone please explain to me step by step how I do this work. I use Eclipse, JAVA EE, No Maven

+7
java rest mailgun
source share
3 answers

I am developing a Java mail library to easily send emails using Mailgun. It can fit your needs.

https://github.com/sargue/mailgun

It allows you to send the following messages:

 MailBuilder.using(configuration) .to(" marty@mcfly.com ") .subject("This is the subject") .text("Hello world!") .build() .send(); 

Even file attachments are easy:

 MailBuilder.using(configuration) .to(" marty@mcfly.com ") .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 messaging and HTML mail helper. This is a young project, feedback is very welcome.

+7
source share

You will need the following dependencies:

You can load 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> 
+1
source share

Perhaps try with this message using the basic implementation of the MailGun API with the Retrofit library: send mail with android without using smtp and user interaction

0
source share

All Articles