Simple Java Mail
Simple Java Mail is the simplest to use lightweight mailing library for Java, while being able to send complex emails including authenticated socks proxy(!), attachments, embedded images, custom headers and properties, robust address validation, build pattern and even DKIM signing and external configuration files with property overriding, Spring support and Email conversion tools. Just send your emails without dealing with RFC's.
The Simple Java Mail library is a thin layer on top of the JavaMail smtp mailing API that allows users to define emails on a high abstraction level without having to deal with mumbo jumbo such as 'multipart' and 'mimemessage'.
EmailBuilder.startingBlank() EmailBuilder.replyingTo(email) EmailBuilder.forwarding(email) EmailBuilder.copying(email)
ConfigLoader.loadProperties("simplejavamail.properties"); // optional default ConfigLoader.loadProperties("overrides.properties"); // optional extra // almost everything is optional: Email email = EmailBuilder.startingBlank() .to("lollypop", "email@example.com") .to("C. Cane", "firstname.lastname@example.org") .ccWithFixedName("C. Bo group", "email@example.com", "firstname.lastname@example.org") .withRecipientsUsingFixedName("Tasting Group", BCC, "email@example.com;firstname.lastname@example.org;tester <email@example.com>") .bcc("Mr Sweetnose <firstname.lastname@example.org>") .withReplyTo("lollypop", "email@example.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("firstname.lastname@example.org") .withBounceTo("email@example.com") .signWithDomainKey(privateKeyData, "somemail.com", "selector") .buildEmail(); Mailer mailer = MailerBuilder .withSMTPServer("smtp.host.com", 587, "firstname.lastname@example.org", "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 available in Maven Central:
<dependency> <groupId>org.simplejavamailgroupId> <artifactId>simple-java-mailartifactId> <version>5.4.0version> dependency>
- #221 API bugfix: server identity verification should not be tied to host trusting
- #226 Bug fix: Attachments with spaces in name are not handled properly
- #218 Enhancement: make Email serializable
- #227 Enhancement: Make parsing recipients from EML file more lenient
- #225 Enhancement: Clarify dependency on Jakarta Activation: DataSources no longer work on Java 9+
- #215 Bug: Current DKIM header canonicalization can lead to invalid DKIM
Note this release should have no impact, but nonetheless is a minor update so you can determine for yourself if this update would cause issues. The release changes DKIM header canonicalization from SIMPLE to RELAXED.
- #219 Bug: MimeMessageParser rejects attachments with duplicate names
- #213 Update from javax.mail:1.6.0 to jakarta.mail:1.6.3
Note that dependencies that switched as well have been updated as part of this change. This includes the optional DKIM library and the email validation library:
- net.markenwerk:utils-mail-dkim (1.1.10 -> 1.2.0)
- com.github.bbottema:emailaddress-rfc2822 (1.1.2 -> 2.1.3)
v5.1.1 - v5.1.7
- v5.1.7 (22-May-2019): #171 Header validation tripping on known safe emails due to References header
- v5.1.6 (27-April-2019): #204 A Concurrent exception when an async process starts when the previous connection pool didn't shutdown in time
- v5.1.6 (27-April-2019): #204 B Exceptions in threads are now caught and logged and don't bubble up anymore. Note that more comprehensive exception handling will be available in 6.0.0 (#148).
- v5.1.5 (24-April-2019): #202 Fixed ConcurrentModificationException when moving invalid embedded images as regular attachments
- v5.1.4 (5-April-2019): #163 Fixed missing mimetype for attachments when parsing Outlook messages where mimeTag was not included
- v5.1.3 (15-Januari-2019): Updated to newer rfc-validator version, which fixed a regression bug in that library
- v5.1.2 (9-Januari-2019): #189 Bugfix for missing timeout config for .testConnection() function
- v5.1.1 (22-December-2018): #190 Fix for transitive dependency clash because of emailaddress-rfc2822 library
- #179 You can now test the connection to the SMTP server
v5.0.1 - v5.0.8
- v5.0.8 (27-Oktober-2018): #178 Fix the annoying vulnerability Github report about spring-core
- v5.0.7 (27-Oktober-2018): #175 Attachment names are not always parsed properly from MimeMessage
- v5.0.6 (3-Oktober-2018): #167 Email addresses validated despite cleared validation validation criteria
- v5.0.5 (3-Oktober-2018): #137 When replying to an email with HTML, the result body is empty
- v5.0.4 (22-September-2018): #168 Properties aquired through ConfigLoader should be typed explicitly and converted if necessary
- v5.0.3 (11-April-2018): #136 ServerConfig class should be public API
- v5.0.2 (7-April-2018): #135 trustingAllHosts should be public on the Builder API
- v5.0.2 (7-April-2018): #131 NamedDataSource should implement EncodingAware
- v5.0.1 (10-March-2018): #130 java.lang.ClassNotFoundException: net.markenwerk.utils.mail.dkim.DkimMessage. Solves the issue of missing optional class DKIM even when not used
Also see the migration notes
- #116 You can now test the connection to the SMTP server
- #115 Create mailers with a very robust MailerBuilder API, able to ignore defaults as well
- #114 Create emails with a very robust EmailBuilder API, able to ignore defaults as well. Now includes support for InternetAddress. Also copy emails.
- #107 You can now easily forward or reply to emails!
- #111 Protocol properties for SMTPS are now applied properly
- #105 SMTP tries to upgrade to TLS while SMTP_TLS now enforces it and for both SMTP_TLS and SMTPS, mail.smtp.ssl.checkserveridentity is set to true
Complete Javadoc overhaul. Navigating the Javadoc should be much more consistent now (builder API being the single public source of truth).
- #122 The email-rfc2822-validator library has been made a proper Maven dependency (not packaged along anymore)
- #120 The DKIM library has been made an optional proper Maven dependency (not packaged along anymore)
- #119 Switched optional Spring dependency version to property and now testing with 4.3.11.RELEASE
- #113 Updated the underlying JavaMail to 1.6.0
- #110 Trusted hosts should be space-delimited
- #109 Email headers should be allowed to be empty (now conversion errors can occur as well)
- #103 Converting to MimeMessage results in an invalid Content-Disposition for attachments
- #101 API backwards compatibility update, reinstate old addRecipient API as deprecated (sorry for removing it abruptly)
API usability release. This relase streamlined the recipient setters, breaking backwards compatibility (but straightforward to fix)
- #95 Feature: Add support native API for setting Return-Receipt-To header
- #93 Feature: Add support native API for setting Disposition-Notification-To header
- #91 Feature: Add support for parsing preformatted email addresses that include both name and address
- #94 Bugfix: A single EmailBuilder would build emails that all share the same collections for recipients, attachments and embedded images
- #98 Bugfix: Subject and body content should be optional
Security and timeout release.
This version safeguards against SMTP injection attack from external values entering the library through Email instance. Also, this release introduces default/configurable timeouts for connecting, reading and writing when sending an email.
- #89 Support multiple delimited recipient addresses sharing the same TO/CC/BCC name
- #88 Safeguard subject property (and others) against SMTP CRLF injection attacks
- #85 Apply configurable timeouts when sending emails
- #83 Parse INLINE attachments without ID as regular attachments when converting (mostly applicable to Apple emails)
#79: Enhancement: define custom message ID on the Email object
#74: v4.2.3-java-6-release: A java6 version with limited capabilities: I've released a customised java6 release with a customised outlook-message-parser 1.1.16-java6-release. This is the last java6 release I will do, as it is simply too much manual labor to create a limited second edition.
For this edition, I've removed the JDK7 Phaser completely which has the following consequences:
- If authenticated proxy is used, the bridging proxy server will not be shut down automatically (and might not run the second time)
- If mails are sent in async mode, the connection pool will not be shut down anymore by itself
This means your server/application might not stop properly due to lingering processes. To be completely safe, only send emails in sync mode (used by default) and don't use authenticated proxy config.
- #73: Patch: fix for sending emails in async mode, which makes sure the connection pool is always closed when the last known email has been sent. Without this fix, the connection pool keeps any parent process running (main thread or Tomcat for example) until a hard kill.
Patch: streamlined convenience methods for adding recipients.
Major feature: Using the EmailConverter you can now convert between Outlook .msg, EML, MimeMessage and Email!
- #66: Feature: convert email to EML
- #65: Feature: read outlook messages from .msg file
- #64: Feature: Added support for logging-only mode that skips the actual sending of emails
- #63: Feature: Already including in previous patch update: Spring support (read properties from Spring context)
- #69: Enhancement: Expanded EmailBuilder API to inlude more options for setting (multiple) recipients
- #70: Enhancement: Most public API now have defensive null-checks for required fields (Fail Fast support)
- #68: Bugfix: Name should be required for embedded images (added safeguards)
- #67: Bugfix: Error when name was omitted for attachment
- minor: added methods on AttachmentResource that reads back the content as (encoded) String
- other: internal testing is now done using Wiser SMTP test server for testing live sending emails
Note: Starting this release, there will always be a Java6 compatible release as well versioned: "x.y.z-java6-release"
- #61: Feature: Add support for providing your own Properties object
- #63: Feature: Spring support (read properties from Spring context)
- #58: Bugfix: Add support for non-English attachment and embedded image names
- #62: Bugfix: Empty properties loaded from config should be considered null
NOTE: ConfigLoader moved from
- #52: bug fix for windows / linux disparity when checking socket status
- #56: bug fix for IOException when signing dkim with a File reference
- #50: bug fix for manual naming datasources
- #48: Added programmatic support trusting hosts for SSL connections
- #47: Honor given names, deduce extension from datasource name, and more robust support for parsing mimemessages
- #41: added support for fast parallel batch processing
- #42: added support for config files
- #43: removed logging implementation dependencies from distribution and documented various sample configs
- #39: simplified and renamed packages to reflect the domain name of the new website: simplejavamail.org
- #38: added support for anonymous proxy
- #38: added support for authenticated proxy
NOTE: All packages have been renamed to "org.simplejavamail.(..)" NOTE: Switched to Java 7
Major feature: DKIM support!
- #36: Added proper toString and equals methods for the Email classes
- #33: Added support for DKIM domain key signing
NOTE: this is the last release still using Java 6. Next release will be using Java 7. /edit: starting with 4.2.0 every release will now have a "x.y.z-java6-release" release as well
- #35: added proper .equals() and .toString() methods
- #34: Fixed bug when disposition is missing (assume it is an attachment)
- other: added findbugs support internally
- #31: Fixed EmailAddressCriteria.DEFAULT and clarified Javadoc
- #30: Improved the demonstration class to include attachments and embedded images
- #29: The package has been restructured for future maintenance, breaking backwards compatibility
- #28: Re-added improved email validation facility
- #22: Added conversion to and from MimeMessage. You can now consume and produce MimeMessage objects with simple-java-mail
- #25: Added finally clause that will always close socket properly in case of an exception
- #24: Updated dependencies SLF4J to 1.7.13 and switched to the updated javax mail package com.sun.mail:javax.mail 1.5.5
- #21: builder API uses CC and BCC recipient types incorrectly
- #19: supporting custom Session Properties now and emergency access to internal Session object.
- #3: turned off email regex validation by default, with the option to turn it back on
- #7: fixed NullPointerException when using your own Session instance
- #10: properly UTF-8 encode recipient addresses
- #14: switched to SLF4J, so you can easily use your own selected logging framework
- #17: Added fluent interface for building emails (see here for an example)
- fixed character encoding for reply-to, from, to, body text and headers (to UTF-8)
- fixed bug where Recipient was not public resulting in uncompilable code when calling email.getRecipients()
- added support for adding open headers, such as 'X-Priority: 2'
- updated for Maven support
- added support for JavaMail's reply-to address
- made port optional as to support port defaulting based on protocol
- added transport strategy default in the createSession method
- tightened up thrown exceptions (MailException instead of RuntimeException)
- added and fixed Javadoc
- Added support for TLS (tested with gmail)
Added support for SSL! (tested with gmail)
- improved argument validation when creating a Mailer without preconfigured Session instance
known possible issue: SSL self-signed certificates might not work (yet). Please let me know by e-mail or create a new issue
Completed migration to Java Simple Mail project.
- removed all Vesijama references
- updated TestMail demonstration class for clarification
- updated readme.txt for test run instructions
- included log4j.properties
- Initial upload to Google Code.