RIFE logo
This page last changed on Apr 17, 2006 by gbevin.

We've extracted the mail queue from our Bamboo forums project and ported it to all the databases that RIFE supports.

This allows you to create mails with simple POJOs and just put them into the queue. At regular intervals, the queue will process them and send them. To be able to use the mail queue, you need to have the javamail and activation jars in your classpath.

The queue is stored in a database and you install the structure as follows:

DatabaseMailQueueFactory.getInstance(datasource).install();

To make the queue run at regular intervals, you have to activate the RIFE's scheduler. It's the easiest to use the in-memory scheduler. You do this by adding the following line to your participants.xml file:

<participant param="rep/scheduler.xml">ParticipantMemoryScheduler</participant>

The rep/scheduler.xml configuration file looks like this if you only have the mail queue task registered:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE scheduler SYSTEM "/dtd/scheduler.dtd">
<scheduler>
    <task classname="com.uwyn.rife.mail.executors.DatabaseMailQueueExecutor" frequency="*/3 * * * *">
        <option name="datasource">postgresql</option>
        <option name="smtp_server">localhost</option>
    </task>
</scheduler>

The format of the frequency attribute is the same as the cron format. The datasource and smtp_server options allow you to configure the mail queue task. If you omit smtp_server, mail will not be sent for real but written to the logging output instead.

To send a mail all you have to do is this, for example:

DatabaseMailQueueFactory.getInstance(datasource).queue(new Email()
    .to("customer@theircompany.com")
    .from("info@yourcompany.com")
    .cc("billing@yourcompany.com")
    .bcc("themanager@yourcompany.com")
    .subject("this is the subject")
    .body("and the body of the mail"));

Support for authentication and SSL

The mail queue executor is able to connected to authenticated SMTP servers and to use SSL for encryption.

The following task options are available for this:

<task classname="com.uwyn.rife.mail.executors.DatabaseMailQueueExecutor"
      frequency="*/5 * * * *">
    <option name="name">...</option>
    <option name="datasource">...</option>
    <option name="smtp_server">...</option>
    <option name="smtp_port">...</option>
     
    <!-- new options -->
    <option name="smtp_ssl"><!-- true or false --></option>
    <option name="smtp_username"><!-- the username for the SMTP server --></option>
    <option name="smtp_password"><!-- the associated password --></option>
</task>
Document generated by Confluence on Oct 19, 2010 14:56