Hey Jason,

have a look at the doc, I supply it on my server (sorry for no-frame support - security header stuff set by apache config): https://cryptearth.de/~cryptearth/doc/org/apache/mailet/base/GenericMailet.html

The doc says this:

init(MailetConfig): "When overriding this form of the method, call super.init(config)." You're using your own private field MailetConfig config - this cause errors as you shadow the private field MailetConfig config in super-class GenericMailet - wich then is "null" when used in other calls. So, if you override init(MailetConfig) itself it is important that the first line in it has to be "super.init(config)" to set the config field in the super class. Also: don't add a field with type MailetConfig and name "config" in your class as this shadow the super field. the better way is you don't override init(MailetConfig) but only init().

Also: The doc says, that GenericMailet.log(String) and GenericMailet.log(String, Throwable) are deprecated and you should use SLF4J. So, this is how your sample should look like:

package com.test;
import javax.mail.MessagingException;
import org.apache.mailet.Mail;
import org.apache.mailet.base.GenericMailet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyMailet extends GenericMailet{
  private static final Logger logger = LoggerFactory.getLogger(MyMailet.class);
  @Override
  public void service(Mail mail) throws MessagingException {
    // log("log via mailet logger with INFO level"); // no longer use this line as log(String) is deprecated     logger.info("Log via slf4j with INFO level !!! Add log4j.logger.com.test=INFO, CONS, FILE in the log4j.properties");     logger.debug("Log via slf4j with DEBUG level !!! Add log4j.logger.com.test=DEBUG, CONS, FILE in the log4j.properties");
  }
}

That's all, fin. No private config field, no override init() - no log() method - just the Logger instance and an info() and a debug().

About log levels: From the top of my head I think about four: debug, info, warn, error. If you set your log-level to debug, you get anything, if you set it only to info or warn you will get way less. I don't try to say you can'T use both, but as the file is named ".properties" I can almost asure you it uses java.util.Properties.load(), wich (IIRC) only parses the first or the last line. So, it you have to lines with key "log4j.logger.com.test" you will only get ONE of them (check the docs if it's the first or the last one). So you can only use one of them. For more info about log level and how to use them please ask google and look up the doc and the site of slf4j and log4j.

Your config doesn't match with your class. You called your class: com.test.CustomMeiletTest (btw: mailet comes from mail - and is therefor written with an A, not with an E) but your config is given: com.test.CustomMeiletTestClassName - this is wrong. If you give a classname it has to exactly match. If you have a class called "CustomMeiletTest" in the package "com.test" then that's "com.test.CustomMeiletTest" - "com.test.CustomMeiletTestClassName" would be a class called "CustomMeiletTestClassName". This is basic java you have to obey. No way around it.

The error log you posted look still in-complete. it should end with a line some like "wrapper stopped" or something like this. It still ends the same where the one you posted already as mail - not helpful.



Last thing: I'm not the one to judge, but header says "X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.24158" (that's outlook express on windows 7 SP1) and "jasonxc...@yahoo.com.INVALID" - so you obvious somehow use a yahoo mail account with outlook express? IDC, I just spotted it by looking for some hint about your attachements, it just looks not right. Don't worry as long as it works (my james would simple reject it as it would mark ".INVALID" as spam).

So long,

Matt

Am 04.07.2019 um 09:45 schrieb Jason Tjankilisan:
Hiya Matt,

Firstly sorry about the mail format, last time I don’t know how to remove or 
any idea to remove CSS Format so for this time im gonna convert them into .txt 
file copy paste it, I gonna use dropbox to share the java file then.
https://www.dropbox.com/s/d4x2rtjh14u6ebw/CustomMeiletTest.java?dl=0 – 
CustomMeiletTest.java

about the Log4j, so that means I can only use one either :
“log4j.logger.com.test=INFO, CONS, FILE” or “log4j.logger.com.test=DEBUG, CONS, 
FILE” ?

I try to comment one of the line and test it for both of them, but still 
nothing works.  I guess it doesn’t work because I didn’t fill in any function 
inside the overridden function maybe? Im still trying to understand what does 
“Level” means. From what I understand, the “Level” mentioned here (DEBUG,INFO) 
means what category is the message displayed.

For the James error, im putting the log error in Txt File also it doesn’t bulk 
the mail with TextWall
https://www.dropbox.com/s/gkfv06o1zixfuf4/JamesErrorLog.log?dl=0 – James Error 
log that I separated from the main james-server.log, the error message inside 
the JamesErrorLog.log text are repeated multiple time in the james-server.log, 
so I just copy paste one pattern of it.

The Mail header thing confuses me as I was using my yahoo ID so I don’t know 
anything about the setting (or maybe I get the wrong idea about it)

I hope all of these information cleared up the confusion from the last message. 
Meanwhile I gonna try to mess around with the setting and try to reset to 
default for the mailet to see where the error comes from.

Sorry for any wrong word, and thank you for the help.

Sincerely, Jason



Sent from Mail for Windows 10

From: cryptearth
Sent: Thursday, July 4, 2019 11:20 AM
To: server-user@james.apache.org
Subject: Re: About Custom Mailet Configuration

Hey Jason,

it seems you either didn't attached the source or don't have permission
to (idk - maybe a list admin could help about this).
So, either you use services like pastebin, an online repo, host it on a
server - or for achive purpose post it here in the mail list.

About your log4j: only add one line, either info or debug - depend on
how deep you need. Finer levels like debug include higher levels like info.
As for exceptions: always print the whole stacktrace - the bit you
posted only says the nested reason is a NPE - but not if it's the main
issue or if there're any other issues. And please try to post it as
TEXTMODE mail excluding those fancy CSS crap - it makes it hard to read
on different devices.

As I've scanned the header you send from jasonxc...@yahoo.com.INVALID -
this doesn't seem right - please check your mail client config. This
could be a reason why your attachements didn't come through.

Matt

Am 04.07.2019 um 05:34 schrieb Jason Tjankilisan:
Hi

So I was reading this tutorial about creating your own custom Mailet
https://james.apache.org/server/3/dev-extend-mailet.html, and from
what i have read, Mailet is a component that process the mail that is
going through the server and can output log whenever something happen
with the Email. Im interested in trying this tutorial to understand
better of mailet works.

So I follow the tutorial, but I had trouble understanding the tutorial
from the lack imagery. Here’s what I’ve done so far

   * Create a java file just like in the “Logging” and add Init ,
     Destroy, getMailetInfo function as the “Configuration” said they
     must have that.
   * Unzip the james-server-mailets-3.3.0.jar from james/lib to get the
     function.
   * Put all on it in one place and use Ant Compile (I didn’t know
     anything about Apache Ant but my friend set it up for me and just
     to type ant when I want to compile) to build it and created the
     jar file from the custom mailet.
   * Put the jar file into james/lib
   * Edit the log4j.properties as mention in the code : added this
   * # Experimental
       o log4j.logger.com.test=INFO, CONS, FILE
       o log4j.logger.com.test=DEBUG, CONS, FILE
       o # ------------

   * Edit the mailetcontainer.xml and comment out the one near that as
     last time I tried it, the connection refused when both of those
     are active.

<!-- Send remaining mails to the transport processor for either local
or remote delivery -->

        <mailet match="All" class="com.test.CustomMeiletTestClassName"/>

<!--

        <mailet match="All" class="ToProcessor">

<processor>transport</processor>

        </mailet>

-->

Some problem occur , the connection still refused and these error show
up at log whenever I use my CustomMeiletTest:

INFO14:31:16,495|
org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor|
Mailet com.test.CustomMeiletTestinstantiated.

WARN14:31:16,515|
org.apache.james.container.spring.context.JamesServerApplicationContext|
/Exception/encountered during context initialization - cancelling
refresh attempt:
/org.springframework.beans.factory.BeanCreationException/:
*Error*creating bean with name 'mailprocessor': Invocation of init
method failed; nested exception is /javax.mail.MessagingException/:
Unable to setup routing for MailetMatcherPairs;

nested exception is:

/java.lang.NullPointerException/

I attach the java code since writing it here gonna make the mail look
so large. Can anyone help what did I do wrong or maybe misunderstand?

Sorry for any wrong word, and thank you for the help.

Sincerely, Jason

Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
Windows 10


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscr...@james.apache.org
For additional commands, e-mail: server-user-h...@james.apache.org

Reply via email to