Hi Benjamin, the init() method is only called, when the "Matcher object" is constructed. It is not called "per mail", it is constructed in the init phase of james. So you cannot access the mail in the init method.
Each time a new mail arrives, the "match(Mail mail)" is called. The match method should return the matching addresses, nothing more. If it returns null, the matcher will "not match" and the Mailet connected to this matcher will not be called. If it matches (and a List of addresses are returned by the matcher), a "Mailet" should handle the mail. You should have a e.g. "GreyListingMailet" extending GenericMailet. Overwrite the method "service(Mail mail)" to handle the mail. Here you could e.g. change the mail object completely. The "architecture" is assumed as 1. A matcher just checks if the mail matches 2. A mailet will be called, if the matcher matches. The Mailet will act on the mail. If the matcher matches, the method "service(Mail mail)" will be called with the actual mail. Normally I would not assume that the matcher does anything with the mail. About the "sender": Be aware of the following facts: - The mail sender could be null or an empty string. Spammers like to do this. - The mail sender could be unparsable, so expect parse exceptions (like javax.mail.internet.AddressException). - There is not only one "sender": There may be a "From:" Header, and a "ResendTo:" header. Both could be assumed to be the sender, depends on you. The mail.getSender() could be different from mail.getMessage().getFrom() or than mail.getMessage().getSender(). - The mail.getMessage().getFrom() is a list of addresses. Technical correct, but not useful. Have a look at "InternetAddress.parseHeader", there is a "strict" and a "non-strict" call. We just implemented our own parsing, to get rid of this parse errors, and used InternetAddress.parseHeader in our own code directly. Maybe you should watch the log for parse errors. Greetings Bernd -----Ursprüngliche Nachricht----- Von: Benjamin Yeo [mailto:ro4drun...@gmail.com] Gesendet: Montag, 16. Mai 2016 19:31 An: server-user@james.apache.org Betreff: Am I able to get the information of the mail sender and receiver? package org.apache.james.transport.matchers; import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Collection; import java.util.HashSet; import java.util.Properties; import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.apache.mailet.GenericMatcher; import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; import java.lang.Class; public class SenderIsGreyList extends GenericMatcher { private Collection senders; public void init() throws MessagingException { //I want to be able to get the information of the mail here.. how do I do it? I want to know the email sender address, email receiver address and then store it in a collection like senders and match it below. I tried to leave everything here empty and went below and I was able to use mail.getSender() and getReceiver to do the matching. How do I do it here so that it can match properly below? } public Collection match(Mail mail) { if (this.senders.contains(mail.getSender())) { return mail.getRecipients(); } else { return null; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org For additional commands, e-mail: server-user-h...@james.apache.org