首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache james mailet无限循环

Apache james mailet无限循环
EN

Stack Overflow用户
提问于 2013-02-23 03:53:36
回答 1查看 369关注 0票数 2

我试图将我的第一个示例mailet部署到apache james v2.3.2,但它进入了一个无穷无尽的循环,即使在重启服务器之后也会一次又一次地给我发送电子邮件。阻止它的唯一方法就是清理假脱机文件夹。

在config.xml中,我按如下方式配置了邮件:

代码语言:javascript
复制
<mailet match="All" class="MyMailet" onMailetException="ignore">
  <supportMailAddress>support@[mydomain].com</supportMailAddress>
</mailet>

我的邮件所做的只是从support@mydomain.com向me@mydomain.com邮箱发送电子邮件:

代码语言:javascript
复制
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";
  }
}

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15032193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档