I tried to deploy my first sample mailet to apache james v2.3.2 but it gets into an endless loop, sending me emails again and again even after restarting the server. The only way to stop it was to clean the spool folder.
In the config.xml I configured my mailet as follows:
<mailet match="All" class="MyMailet" onMailetException="ignore">
<supportMailAddress>support@[mydomain].com</supportMailAddress>
</mailet>
All my mailet does is email from support@[mydomain].com to a me@[mydomain].com mailbox:
public class MyMailet extends GenericMailet {
private MailAddress supportMailAddress;
public void init() throws ParseException {
supportMailAddress = new MailAddress(getInitParameter("supportMailAddress"));
}
public void service(Mail mail) throws MessagingException {
MailAddress sender = mail.getSender();
MailAddress realMailbox = new MailAddress("me@[mydomain].com");
try {
sendToRealMailbox(mail, realMailbox);
} catch (MessagingException me) {
me.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
mail.setState(Mail.GHOST);
}
private void sendToRealMailbox(Mail mail, MailAddress realMailbox) throws MessagingException, IOException {
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
message.setFrom(supportMailAddress.toInternetAddress());
message.setRecipient(Message.RecipientType.TO, realMailbox.toInternetAddress());
message.setSubject("MyMailet: " + mail.getMessage().getSubject());
message.setText("MyMailet: message body");
message.setSentDate(new Date());
Collection recipients = new Vector();
recipients.add(realMailbox);
getMailetContext().sendMail(supportMailAddress, recipients, message);
}
public String getMailetInfo() {
return "MyMailet";
}
}
What am I doing wrong?