Skip to content

everit-org/email-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

email-api

API for handling e-mails in Java.

Usage

Setting the subject, the sender and the recipients

Email email = new Email().withSubject("I need coffee");

// Add the sender with builder pattern
email.from = new EmailAddress().withAddress("[email protected]").withPersonal("Foo Bar");

// Add some recipients with builder pattern
email.recipients = new Recipients()
    .withTo(Arrays.asList(new EmailAddress[] {
        new EmailAddress().withAddress("[email protected]")}))
    .withCc(Arrays.asList(new EmailAddress[] {
        new EmailAddress().withAddress("[email protected]")}));

Adding text content

email.withTextContent("I really need coffee");

Adding html content with an inline image

Map<String, Attachment> inlineImages = new HashMap<>;

inlineImages.put("ineedcoffee", new Attachment()
    .withContentType("image/jpg")
    .withName("ineedcoffee.jpg"
    .withInputStreamSupplier(() -> new FileInputStream("/tmp/ineedcoffee.jpg"))));


email.withHtmlContent(new HtmlContent()
    .withHtml("<h1>I really need coffee</h1>"
        + "<img src='cid:ineedcoffee' />")
    .withInlineImageByCidMap();

Adding attachments

email.withAttachments(Arrays.aslist(
    new Attachment()
        .withContentType("application/pdf")
        .withName("readme.pdf"
        .withInputStreamSupplier(() -> new FileInputStream("/tmp/readme.pdf"))));

Sending emails

EmailSender emailSender = getSomeEmailSenderImplementation();
emailSender.sendEmail(email);

At the moment, an implementation based on JavaMail API is available. In the future, we are planning to have a more lightweight module that implements the necessary parts of SMTP protocol directly.

About

API for handling e-mails in Java.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages