我尝试将我的第一个示例邮件部署到 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";
}
}
我做错了什么?
最佳答案
您使用了匹配器“All”,即
<mailet match="All">
这告诉 James 对所有电子邮件运行此邮件。因此,当您将第一封电子邮件发送至support@[mydomain].com
时,邮件触发并向 me@[mydomain].com
发送一封电子邮件。电子邮件发送至 me@[mydomain].com
导致邮件再次触发并发送另一封电子邮件至 me@[mydomain].com
,这会导致邮件再次触发,等等...
尝试使用“RecipientIs”匹配器,即
<mailet match="RecipientIs=support@[mydomain].com">
仅当电子邮件到达 support@[mydomain].com 时才会触发邮件。
关于loops - Apache james mailet 无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032193/