Upgrading to 5.0.0? Read the migration notes.
Simple Java Mail is a 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.
EmailBuilder.startingBlank()
EmailBuilder.replyingTo(email)
EmailBuilder.forwarding(email)
EmailBuilder.copying(email)
// Most essentials together (but almost everything is optional):
ConfigLoader.loadProperties("simplejavamail.properties"); // optional default
ConfigLoader.loadProperties("overrides.properties"); // optional extra
Email email = EmailBuilder.startingBlank()
.to("lollypop", "lolly.pop@somemail.com")
.to("C. Cane", "candycane@candyshop.org")
.ccWithFixedName("C. Bo group", "chocobo1@candyshop.org", "chocobo2@candyshop.org")
.withRecipientsUsingFixedName("Tasting Group", BCC,
"taster1@cgroup.org;taster2@cgroup.org;tester <taster3@cgroup.org>")
.bcc("Mr Sweetnose <snose@candyshop.org>")
.withReplyTo("lollypop", "lolly.pop@othermail.com")
.withSubject("hey")
.withHTMLText("<img src='cid:wink1'><b>We should meet up!</b><img src='cid:wink2'>")
.withPlainText("Please view this email in a modern email client!")
.withEmbeddedImage("wink1", imageByteArray, "image/png")
.withEmbeddedImage("wink2", imageDatesource)
.withAttachment("invitation", pdfByteArray, "application/pdf")
.withAttachment("dresscode", odfDatasource)
.withHeader("X-Priority", 5)
.withReturnReceiptTo()
.withDispositionNotificationTo("notify-read-emails@candyshop.com")
.withBounceTo("tech@candyshop.com")
.signWithDomainKey(privateKeyData, "somemail.com", "selector")
.buildEmail();
Mailer mailer = MailerBuilder
.withSMTPServer("smtp.host.com", 587, "user@host.com", "password")
.withTransportStrategy(TransportStrategy.SMTP_TLS)
.withProxy("socksproxy.host.com", 1080, "proxy user", "proxy password")
.withSessionTimeout(10 * 1000)
.clearEmailAddressCriteria() // turns off email validation
.withProperty("mail.smtp.sendpartial", true)
.withDebugLogging(true)
.buildMailer();
mailer.sendMail(email);
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!