Dashboard > RIFE > ... > Cook Book > Mail queue
RIFE Log In | Sign Up   View a printable version of the current page.
Mail queue


Added by Geert Bevin, last edited by Geert Bevin on Apr 17, 2006  (view change)
Labels: 
(None)

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>

Is it possible to send HTML format mail using this Mail Queue feature?
If yes how?

Posted by Narendra Jain at Apr 25, 2006 06:52 | Permalink

Hi Nerandra,

yes, please check out the related Javadoc

Posted by Geert Bevin at Apr 25, 2006 08:16 | Permalink

Not mentioned anywhere that I've seen, two external libraries are needed in order to make the email scheduler work: the Java Mail API and the Java Activation Framework (JAF). Without the first you won't be able to compile programs that send mail (javax.mail.* will be missing). Without the JAF however you'll get cryptic messages from the scheduler about javax/activation/Datasouce not being found coming from DatabaseMailQueueExecutor.java's gotBeanInstance() method.

Posted by David HM Spector at Dec 19, 2006 07:48 | Permalink


Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators