API for handling e-mails in Java.
Email email = new Email().withSubject("I need coffee");
// Add the sender with builder pattern
email.from = new EmailAddress().withAddress("foo@bar.com").withPersonal("Foo Bar");
// Add some recipients with builder pattern
email.recipients = new Recipients()
.withTo(Arrays.asList(new EmailAddress[] {
new EmailAddress().withAddress("target@bar.com")}))
.withCc(Arrays.asList(new EmailAddress[] {
new EmailAddress().withAddress("cc@bar.com")}));
email.withTextContent("I really need coffee");
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();
email.withAttachments(Arrays.aslist(
new Attachment()
.withContentType("application/pdf")
.withName("readme.pdf"
.withInputStreamSupplier(() -> new FileInputStream("/tmp/readme.pdf"))));
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.