Skip to content

Instantly share code, notes, and snippets.

@todvora
Created August 14, 2014 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todvora/379d7e69bf353a8776bf to your computer and use it in GitHub Desktop.
Save todvora/379d7e69bf353a8776bf to your computer and use it in GitHub Desktop.
Mailgun Java Example
public static Response SendSimpleMessage() {
Client client = ClientBuilder.newClient();
client.register(HttpAuthenticationFeature.basic("api", "key-################################"));
WebTarget target = client.target("https://api.mailgun.net/v2/sandbox################################.mailgun.org/messages");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", "Mailgun Sandbox <postmaster@sandbox################################.mailgun.org>");
formData.add("to", "Tomas Dvorak <todvora@gmail.com>");
formData.add("subject", "Hello Tomas Dvorak");
formData.add("text", "Congratulations Tomas Dvorak, you just sent an email with Mailgun! You are truly awesome! You can see a record of this email in your logs: https://mailgun.com/cp/log . You can send up to 300 emails/day from this sandbox server. Next, you should add your own domain so you can send 10,000 emails/month for free.");
return target.request(MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(formData));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment