Simple Java Mail: Simple API, Complex Emails


Simple Java Mail is mailing library with a super clean API. It's the easiest to use Java mailing library in the world.


This library relieves you of having to deal with low level API such as MimeMessage, fuzzy try catch constructions, inner classes and other nonsense. You just want to send an email!


But don't let looks deceive you, this library does everything: it is a feature complete mailing library, yet it is small and lightweight. It is fully RFC compliant and looks good in all email clients.


It's also the only java mailing library in the world that can send through authenticated SOCKS proxy.

// Everything together:

ConfigLoader.loadProperties("simplejavamail.properties"); // optional default
ConfigLoader.loadProperties("overrides.properties"); // optional extra

Email email = new Email();

email.addRecipient("lollypop", "lolly.pop@somemail.com", Message.RecipientType.TO);
email.setReplyToAddress("lollypop", "lolly.pop@othermail.com");
email.addRecipient("C. Cane", "candycane@candyshop.org", Message.RecipientType.TO);
email.addRecipient("C. Bo", "chocobo@candyshop.org", Message.RecipientType.CC);
email.setSubject("hey");
email.setText("We should meet up! ;)");
email.setTextHTML("<img src='cid:wink1'><b>We should meet up!</b><img src='cid:wink2'>");
email.addEmbeddedImage("wink1", imageByteArray, "image/png");
email.addEmbeddedImage("wink2", imageDatesource);
email.addAttachment("invitation", pdfByteArray, "application/pdf");
email.addAttachment("dresscode", odfDatasource);

email.signWithDomainKey(privateKeyData, "somemail.com", "selector");

new Mailer(
		new ServerConfig("smtp.host.com", 587, "user@host.com", "password"),
		TransportStrategy.SMTP_TLS,
		new ProxyConfig("socksproxy.host.com", 1080, "proxy user", "proxy password")
).sendMail(email);
§

Getting started

Simple Java Mail is a thin layer on top of Oracle's SMTP JavaMail API. For logging purposes, SLF4J is used so you can use whatever logging framework you prefer.

Once the dependencies are set up, simply copy the above examples and start mailing!

Show Examples API Javadoc