All Projects → sargue → Mailgun

sargue / Mailgun

Licence: mit
Java library to easily send emails using the Mailgun service

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Mailgun

Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (+100.71%)
Mutual labels:  mailgun
Laravel Mailguneu
Allow customising the Mailgun server URL to use EU servers.
Stars: ✭ 13 (-90.71%)
Mutual labels:  mailgun
Mailcore
Emailing wrapper for Vapor 3 apps
Stars: ✭ 77 (-45%)
Mutual labels:  mailgun
Airform
Functional HTML forms for Front-End Developers.
Stars: ✭ 307 (+119.29%)
Mutual labels:  mailgun
Laravel Mailbox
Catch incoming emails in your Laravel application
Stars: ✭ 783 (+459.29%)
Mutual labels:  mailgun
Gympoint Api
Rest API of a gym management application - built with Express, Postgres, Redis, and Nodemailer.
Stars: ✭ 39 (-72.14%)
Mutual labels:  mailgun
bulk-mail-cli
Do quick, hassle-free email marketing with this small but very powerful tool! 🔥
Stars: ✭ 88 (-37.14%)
Mutual labels:  mailgun
Suet
An analytics dashboard and reporting tool for Mailgun and Amazon SES transactional emails.
Stars: ✭ 114 (-18.57%)
Mutual labels:  mailgun
Mailgun Js Boland
A simple Node.js helper module for Mailgun API.
Stars: ✭ 895 (+539.29%)
Mutual labels:  mailgun
Django Anymail
Django email backends and webhooks for Amazon SES, Mailgun, Mailjet, Postmark, SendGrid, Sendinblue, SparkPost and more
Stars: ✭ 1,109 (+692.14%)
Mutual labels:  mailgun
Omnimail
Send email across all platforms using one interface
Stars: ✭ 325 (+132.14%)
Mutual labels:  mailgun
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+419.29%)
Mutual labels:  mailgun
Mailgun Mailer
Provides Mailgun integration for Symfony Mailer
Stars: ✭ 41 (-70.71%)
Mutual labels:  mailgun
Grunt Email Workflow
A Grunt workflow for designing and testing responsive HTML email templates with SCSS.
Stars: ✭ 3,010 (+2050%)
Mutual labels:  mailgun
Mailgun
📧 Service to assist with sending emails from Vapor apps
Stars: ✭ 82 (-41.43%)
Mutual labels:  mailgun
mailgun-plsql-api
Oracle PL/SQL API for Mailgun
Stars: ✭ 30 (-78.57%)
Mutual labels:  mailgun
Goeat Api
Rest API for a food delivery application - Built with Express, Postgres, Redis, MongoDB and Nodemailer
Stars: ✭ 36 (-74.29%)
Mutual labels:  mailgun
Fluentemail
All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
Stars: ✭ 1,888 (+1248.57%)
Mutual labels:  mailgun
Slmmail
Send mail from Laminas or Mezzio using external mail services.
Stars: ✭ 106 (-24.29%)
Mutual labels:  mailgun
Parse Server Mailgun
Allows your Parse Server app to send template-based emails through Mailgun. Just add your template files (plain text and html) to the email adapter's configuration.
Stars: ✭ 53 (-62.14%)
Mutual labels:  mailgun

Mailgun Java library

Javadocs Build Status License Download

Introduction

What is this?

This is a small Java library to ease the sending of email messages using the great Mailgun service. It uses the RESTful Java client library Jersey.

What is Mailgun?

An email sending service with a REST API.

What is Jersey?

A RESTful java library. Actually, the reference implementation of JAX-RS, the standard API for RESTful web services for Java.

Installation

Add the dependency to your project:

Gradle

implementation 'net.sargue:mailgun:1.9.2'

Maven

<dependency>
    <groupId>net.sargue</groupId>
    <artifactId>mailgun</artifactId>
    <version>1.9.2</version>
</dependency>

A note about dependencies

This project depends on the Jersey library (see above). The Jersey library is part of the bigger glassfish/Oracle ecosystem which apparently doesn't have top notch compatibility very high on its priority list.

Said so, you may encounter problems with dependencies as there are some libraries which are repackaged under different Maven coordinates and will leak duplicates on your classpath.

Please, see issue #1 for details and workarounds. Thanks for your understanding.

Usage

The library is pretty straighforward. You just need to remember two classes:

  • Configuration: which usually is a singleton you build once and re-use
  • Mail: the entry point to build and send emails
  • MailContent: an optional helper to build HTML and text message bodys

That were three classes but the last one is optional although very useful if you want to send some simple messages in HTML.

The library is built to be used as a fluent interface, almost a DSL, so the code is quite self explanatory.

Javadocs

You can browse the javadocs published thanks to the great javadoc.io service.

Requirements and dependencies

Requires Java 7+.

Depends on Jersey 2 client.

Android support

There is not. Android is not officially supported. I have no experience on Android development so I won't be able to help much on any issue. There are a number of issues raised which indicate that the library can be used on Android but YMMV.

The main issue about using this library on android is the repackaging of some packages done by Jersey, like javax.inject. If using gradle you could try to add this:

configurations {
    all*.exclude group: 'org.glassfish.hk2.external', module:'javax.inject'
}

Anyway try it and if you find a problem please report it. I will try to help.

Configuration

First of all you need to prepare a Configuration object used by the library.

Usually you can do this once and keep the same object for all your calls. It is thread safe.

Configuration configuration = new Configuration()
    .domain("somedomain.com")
    .apiKey("key-xxxxxxxxxxxxxxxxxxxxxxxxx")
    .from("Test account", "[email protected]");

Sending a basic email

Mail.using(configuration)
    .to("[email protected]")
    .subject("This is the subject")
    .text("Hello world!")
    .build()
    .send();

Sending an email with an attachment

Mail.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();

More examples

Some fields (more or less the ones that make sense) can be repeated. Like to() to send to multiple recipients, attachment() to include more than one attachment and so on.

Mail.using(configuration)
    .to("[email protected]")
    .to("[email protected]")
    .cc("[email protected]")
    .cc("[email protected]")
    .subject("This is the subject")
    .text("Hello world!")
    .build()
    .send();
Mail.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"))
    .attachment(new File("/path/to/report.pdf"))
    .build()
    .send();

Advanced content using content helpers

The classes on the package net.sargue.mailgun.content are designed to easily build basic HTML messages. It's not supposed to be used for building cutting edge responsive modern HTML messages. It's just for simple cases where you need to send a message and you want to use some basic HTML like tables and some formatting.

Some self explanatory examples:

Mail.using(configuration)
    .body()
    .h1("This is a heading")
    .p("And this some text")
    .mail()
    .to("[email protected]")
    .subject("This is the subject")
    .build()
    .send();
Mail.using(configuration)
    .body()
    .h3("Monthly report")
    .p("Report of the number of time travels this month")
    .table()
        .row("Marty", "5")
        .row("Doc", "7")
        .row("Einstein", "0")
    .end()
    .mail()
    .to("[email protected]")
    .subject("Monthly Delorean usage")
    .build()
    .send();

Of course you can keep the body content and mail building separated.

Body body = Body.builder()
                .h1("This is a heading")
                .p("And this some text")
                .build();

Mail.using(configuration)
    .to("[email protected]")
    .subject("This is the subject")
    .content(body)
    .build()
    .send();

There is also a very powerful extension mechanism which are the content converters. Check it out with some more information about the these classes in the wiki.

Changelog

The changelog is in a separate page.

Test suite

There is a test suite using WireMock to mock the Mailgun REST API endpoint.

The mail content test suite is a work in progress right now.

Contributing

All contributions are welcome. Use the issues section to send feature requests. Pull requests are also welcome, just try to stick with the overall code style and provide some tests if possible.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].