loops - Apache james mailet 无限循环

标签 loops infinite-loop james

我尝试将我的第一个示例邮件部署到 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 时才会触发邮件。

查看此list of James matchers with examples .

关于loops - Apache james mailet 无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032193/

相关文章:

c - 无限循环会导致系统崩溃吗?

java - Java While 循环中的奇怪行为

javascript - 使用 jquery 循环列表 - 轮播效果

javascript - 如何迭代数组中的每个数字并将它们与同一数组中的其他数字相加 - JS

python - 如何加快大字典的迭代速度

c - 为什么 while(true) 是无限循环?

email - Java MimeMessage 到带有所有附件的 eml 文件

java - 使用 Apache James 实现客户端身份验证

java - 如何连接到 Apache James 的用户存储库并通过 Java 代码检索用户列表?

java - 从文件读取时出现循环问题