我尝试将我的第一个示例 mailet 部署到 apache james v2.3.2,但它进入了一个无限循环,即使在重新启动服务器后一次又一次地向我发送电子邮件。阻止它的唯一方法是清理假脱机文件夹。
在 config.xml 中,我按如下方式配置了我的 mailet:
<mailet match="All" class="MyMailet" onMailetException="ignore">
<supportMailAddress>support@[mydomain].com</supportMailAddress>
</mailet>
我的 mailet 所做的只是从 support@[mydomain].com 向 me@[mydomain].com 邮箱发送电子邮件:
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";
}
}
我究竟做错了什么?