Hi,
I found the way, thanks to the documentation and trial and error method.
1) Created a file /etc/amavis/conf.d/my-custom-hook.conf:
===========================================================
package Amavis::Custom;
use strict;
use warnings;
no warnings qw(uninitialized redefine);
use DBI qw(:sql_types);
use DBD::mysql;
BEGIN {
import Amavis::Conf qw(:platform :confvars c cr ca $myhostname);
import Amavis::Util qw(do_log untaint safe_encode safe_decode);
import Amavis::rfc2821_2822_Tools;
import Amavis::Notify qw(build_mime_entity);
}
sub new {
my($class,$conn,$msginfo) = @_;
my($self) = bless {}, $class;
my($conn_h) = Amavis::Out::SQL::Connection->new(
['DBI:mysql:database=mydb;host=127.0.0.1', 'user', 'password'] );
$self->{'conn_h'} = $conn_h;
$self; # returning an object activates further callbacks,
# returning undef disables them
}
sub before_send {
my($self,$conn,$msginfo) = @_;
# $self ... whatever was returned by new()
# $conn ... object with information about a SMTP connection
# $msginfo ... object with info. about a mail message being processed
my($ll) = 2; # log level (0 is the most important level, 1, 2,... 5 less so)
do_log($ll,"CUSTOM: new message");
my($sender) = $msginfo->sender; # envelope sender address, e.g. '***@e.com'
do_log($ll,"CUSTOM: Envelope sender: <%s>", $sender);
}
1;
===========================================================
2) Added the following in the /etc/amavis/conf.d/50-user :
include_config_files('/etc/amavis/conf.d/my-custom-hook.conf');
3) Ensured log level set to 2 (according to the code above) in the /etc/amavis/conf.d/50-user :
$log_level = 2;
4) Restarted Amavis:
sudo /etc/init.d/amavis restart
I verified it by sending mail to the MTA (Postfix) and checking the entry in /var/log/mail.log
Hope it helps!
Regards,
Sam