2

最初のサンプル メールレットを 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";
  }
}

私は何を間違っていますか?

4

1 に答える 1

2

マッチャー「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 に届いた場合にのみメールレットが起動されます。

このJames マッチャーのリストと例を参照してください。

于 2013-04-12T19:42:44.547 に答える