GALIP SOKULLU wrote on Saturday, October 18, 2003:

>     Here comes a newbie question...

Hey, so am I!  Just installed James for the first time last week, but I have written a 
Mailet.  You can enjoy the sample, and I can get feedback if I did something really 
dumb.

> Can anyone write a simple mailet code sample ? I've searched on the
> net for a sample code of mailet but I 
>couldn't find anything. I want a very simple example... how it works?

This is a simplified version of my first mailet.  It simply inserts a Reply-To header 
into the mail message.  What it inserts is configured by the contents of the 
config.xml file...

>How should I configure config.xml ?
> 
> Let's say I have written a mailet named "distribute.class" .. Where
> should I put it ? And how do I call it 
>from config.xml ?
>         
>       <mailet match="All" class="ToProcessor">
>            <processor> ??? </processor>
>         </mailet>

    <mailet match="All" class="ReplyTo">
        <replyto>[EMAIL PROTECTED]</replyto>
        <comment>The Reply-To was inserted by the ReplyTo mailet</comment>
    </mailet>

----

//
//  ReplyTo.java
//  ReplyTo
//
//  Created by James Bucanek on Wed Oct 15 2003.
//  Copyright (c) 2003 Twilight & Barking Software
//
package net.listmoms.mailets;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

import org.apache.mailet.*;

/**
 * Mailet that inserts a Reply-To header.
 *
 * This mailet inserts a static address
 * specified by the <code>replyto</code> parameter.<br>
 *
 * If a <code>comment</code> parameter is specified,
 * it will also add that as a <code>Comment:</code> header.
 */

public class ReplyTo extends GenericMailet
    {
    public static final String REPLY_PARAMETER = "replyto";
    public static final String COMMENT_PARAMETER = "comment";
    
    private InternetAddress replyTo;
    private String          comment;

    public void init( MailetConfig newConfig ) throws MessagingException
        {
        super.init(newConfig);

        String address = newConfig.getInitParameter(REPLY_PARAMETER);
        try
            {
            if (address!=null)
                replyTo = new InternetAddress(address);
            }
        catch (AddressException ae)
            {
            log("Error parsing reply-to parameter: "+address,ae);
            }
        
        if (replyTo==null)
            log("Requires a 'replyto' parameter: mailet will do nothing");

        comment = newConfig.getInitParameter(COMMENT_PARAMETER);
        }
    
    public void service( Mail mail ) throws MessagingException
        {
        if (replyTo!=null)
            {
            mail.getMessage().setReplyTo(new Address[] { replyTo });
            if (comment!=null)
                mail.getMessage().setHeader("Comment",comment);
            }
        }

    public String getMailetInfo()
        {
        return ("Reply-To mailet, version 0.1, written by James Bucanek, 15-Oct-2003");
        }

    }
______________________________________________________
James Bucanek       <mailto:[EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to