HA-JavaMail
 
SourceForge.net logo
Support This Project logo
Built with Apache Forrest logo
  Font size:      
 

HA-JavaMail: High-Availability JavaMail

PDF
PDF

Introduction

HA-JavaMail is a JavaMail transport proxy that adds efficiency and reliability to an underlying JavaMail provider.

HA-JavaMail is NOT an SMTP implementation - it's a wrapper around an existing implementation that provides several client-side optimizations designed to maximize throughput.

Features

  • High-Availibility
    • Manages connections to multiple mail servers.
    • Message sending will retry with the next available transport until successful.
    • Detected dead connections are automatically re-opened and made available.
  • Efficiency
    • Messages are sent asynchronously to minimize impact of network latency between client and mail server.
    • Configurable sending strategies, e.g. email address host grouping minimizes work required to lookup domains.
  • Tranparent integration
    • Implements the javax.mail.Transport interface
    • Integration is as simple as placing HA-JavaMail jar file into classpath.

Sample Usage

e.g.

java.util.Properties properties = new java.util.Properties();
properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.host", "mail1.domain.com,mail2.domain.com");
properties.setProperty("mail.transport.pool-size", "10");

javax.mail.Session session = javax.mail.Session.getInstance(properties);
javax.mail.Transport transport = session.getTransport();

long startTime = System.currentTimeMillis();

transport.connect();

javax.mail.Address address = new javax.mail.internet.InternetAddress("test@domain.com");

for (int i = 1; i ≤ 100; ++i)
{
    javax.mail.Message message = new javax.mail.internet.MimeMessage(session);
    message.setRecipient(javax.mail.Message.RecipientType.TO, address);
    message.setSubject("Test #" + i);
    message.setText("");

    transport.sendMessage(message, message.getAllRecipients());
}

transport.close();

long endTime = System.currentTimeMillis();
System.out.println("Total execution time = " + (startTime - endTime) + " ms");

Configuration

HA-JavaMail is configured entirely via session properties.

Session Property Default Description
mail.host or mail.protocol.host Required Comma seperated list of mail server host names.
mail.transport.pool-size 1 Number of connections to manage per server.
mail.transport.connect-timeout 0 Number of seconds to wait for the first successful transport connection before timing out. 0 means wait forever.
mail.transport.connect-retry-period 60 Number of seconds to wait between transport connection attempts.
mail.transport.sender-strategy net.sf.hajavamail.SimpleSenderStrategy net.sf.hajavamail.SenderStrategy implementation used to send mail. Also available out of the box is net.sf.hajavamail.HostGroupingSenderStrategy.

Performance

Using HA-JavaMail in conjunction with Sun's JavaMail implementation is significantly faster than Sun's JavaMail implementation alone.

Note: HA-JavaMail (number of servers * Pool size)



Valid HTML 4.01!Valid CSS!