我试图将我的第一个示例mailet部署到apache james v2.3.2,但它进入了一个无穷无尽的循环,即使在重启服务器之后也会一次又一次地给我发送电子邮件。阻止它的唯一方法就是清理假脱机文件夹。
在config.xml中,我按如下方式配置了邮件:
<mailet match="All" class="MyMailet" onMailetException="ignore">
<supportMailAddress>support@[mydomain].com</supportMailAddress>
</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";
}
}我做错了什么?
发布于 2013-04-13 03:42:45
您使用了匹配器"All",即
<mailet match="All">
这将告诉James对所有电子邮件运行此mailet。因此,当您向support@[mydomain].com发送第一封电子邮件时,邮件将触发并向me@[mydomain].com发送一封电子邮件。进入me@[mydomain].com的电子邮件导致邮件再次发射,并向me@[mydomain].com发送另一封电子邮件,这导致邮件再次发射,依此类推...
尝试使用"RecipientIs“匹配器,例如
<mailet match="RecipientIs=support@[mydomain].com">
这将仅当电子邮件到达support@mydomain.com时触发邮件。
请参阅此list of James matchers with examples。
https://stackoverflow.com/questions/15032193
复制相似问题