Skip to content

Commit

Permalink
Fix for #19: adding support for custom Session Properties and providi…
Browse files Browse the repository at this point in the history
…ng emergency access to Session instance
  • Loading branch information
bbottema committed Jul 21, 2015
1 parent 961347d commit 5ee0968
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/java/org/codemonkey/simplejavamail/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Mailer(final String host, final Integer port, final String username, fina
* @see TransportStrategy#propertyNameUsername()
* @see TransportStrategy#propertyNameAuthenticate()
*/
public Session createMailSession(final String host, final Integer port, final String username, final String password) {
protected Session createMailSession(final String host, final Integer port, final String username, final String password) {
if (transportStrategy == null) {
logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
transportStrategy = TransportStrategy.SMTP_PLAIN;
Expand Down Expand Up @@ -200,15 +200,34 @@ public Mailer(final String host, final Integer port, final String username, fina
this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
}

/**
* In case Simple Java Mail falls short somehow, you can get a hold of the internal {@link Session} instance to debug or tweak. Please
* let us know why you are needing this on https://github.com/bbottema/simple-java-mail/issues.
*/
public Session getSession() {
logger.warn("Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it.");
logger.warn("\t>https://github.com/bbottema/simple-java-mail/issues");
return session;
}

/**
* Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
*
* @param debug Flag to indicate debug mode yes/no.
*/
public void setDebug(boolean debug) {
public void setDebug(final boolean debug) {
session.setDebug(debug);
}

/**
* Copies all property entries into the {@link Session} using {@link Session#getProperties()}.
*
* @param properties The source properties to add or override in the internal {@link Session} instance.
*/
public void applyProperties(final Properties properties) {
session.getProperties().putAll(properties);
}

/**
* Processes an {@link Email} instance into a completely configured {@link Message}.
* <p>
Expand Down

0 comments on commit 5ee0968

Please sign in to comment.