メール設定 · 11 min read · Jan 04, 2026

Postfix、Courier、MySQLを使用した仮想ユーザーおよびドメインに伴う自動応答機能

Postfix、Courier、MySQLを使用した仮想ユーザーおよびドメインに伴う自動応答機能

このガイドは、Debian SargeでYaa!(Yet Another Autoresponder!)を動作させ、Postfixチュートリアルの仮想ユーザーに関するものです(https://www.howtoforge.com/virtual_postfix_mysql_quota_courierを参照)。

ガイドについて理解すべき最初のことは、Virtual Delivery Agent (VDA)を使用しているため、.forwardファイルを介してパイプに渡すことで使用できる自動応答機能は、VDAが.forwardの展開をサポートしていないため、単純に機能しないということです。この制限は、Procmail/Maildrop配信を介して克服できますが、それは煩雑で、特に多く使用されるメールシステムでは遅くなります。簡単な答えはYaa!です。

Yaaをダウンロードしてパーティーを始めましょう:

mkdir -p /usr/local/postfix-tools 
cd  /usr/local/postfix-tools
wget http://frost.ath.cx/software/yaa/dist/yaa-0.3.tar.bz2
tar jxvf yaa-0.3.tar.bz2

次に、Yaaが動作するために必要なPerlモジュールを取得する必要があります。Yaaはデーモンモードの両方で動作しますが、このガイドではプログラムの非デーモンモードにのみ関心を持ちます。

apt-get install libmldbm-perl libio-lockedfile-perl  libnet-perl libcarp-clan-perl libdbi-perl libdbd-mysql-perl libnet-server-perl libio-stringy-perl

Yaaが動作するようにデータベース構造を設定しましょう:

mysql -uroot -p
use mail;
CREATE TABLE `autoresponder` (  
`active` tinyint(1) NOT NULL default '0',  
`message` mediumtext NOT NULL,  
`subject` varchar(250) NOT NULL default '',  
`charset` varchar(250) NOT NULL default '',  
`forward` varchar(250) NOT NULL default '',  
`address` varchar(250) NOT NULL default '',  
`local_domains` varchar(250) NOT NULL default '',  
`tstart` int(32) NOT NULL default '0',  
`tfinish` int(32) NOT NULL default '0',  
PRIMARY KEY (`address`),  
KEY `active` (`active`),  
KEY `tstart` (`tstart`,`tfinish`)  
)
quit;

次に、Postfixを構成してYaa!をトランスポート経由で呼び出す必要があるため、/etc/postfix/master.cfを編集して以下を追加します:

 # yaa autoresponder  
yaa     unix    -       n       n       -       -       pipe  
                                                        user=vmail  
                                                        argv=/usr/local/postfix-tools/yaa-0.3/bin/yaa.pl

変更を有効にするためにPostfixを再起動しましょう:

/etc/init.d/postfix restart

最後にYaa!を構成する必要があります。簡単にするために、私のyaa.confを提供しました。

######################################################  
#                 !!!!WARNING!!!!                    #  
#  DO NOT REMOVE OR COMMENT OUT THE FOLLOWING LINE   #  
use strict;                                          #  
######################################################  

# NOTICE:  
# If you're having trouble running yaa.pl and you're  
# not shure, what's going wrong, set environment varibale  
#  
#                   YAA_DEBUG  
#  
# and run yaa.pl again with the same arguments/configuration file.  
#  
# Yaa debug output will be written to stderr if running in single  
# message processing mode or in daemon mode with $daemon_background = 0.  
#   
# If you're running in daemon mode with $daemon_background = 1, debug messages  
# will be sent to logger subsystem if it's enabled.  
#  
# example for csh:  
# setenv YAA_DEBUG 1  
#  
# example for sh/ksh/bash:  
# export YAA_DEBUG=1  
#  


# GENERAL NOTES  
#   
# excerpt taken from configuration file of excellent opensource project  
# called amavisd-new   
# by Mark Martinec .  
#   
#  This file is a normal Perl code, interpreted by Perl itself.  
#  - make sure this file (or directory where it resides) is NOT WRITABLE  
#    by mere mortals, otherwise it represents a severe security risk!  
#  - for values which are interpreted as booleans, it is recommended  
#    to use 1 for true, and 0 or undef or '' for false.  
#  - Perl syntax applies. Most notably: strings in "" may include variables  
#    (which start with $ or @); to include characters @ and $ in double  
#    quoted strings, precede them by a backslash; in single-quoted strings  
#    the $ and @ lose their special meaning, so it is usually easier to use  
#    single quoted strings. Still, in both cases backslash needs to be doubled.  


######################################################  
#           LOGGING SUBSYSTEM SETTINGS               #  
######################################################  

# enable logging?  
# type: boolean  
# default: 1  
# $logging = 1;  

# enable logging to syslog?  
# type: boolean  
# default: 1  
$log_syslog = 1;  

# syslog logging facility  
# type: string  
# default: "mail"  
# this setting applies only when logging to syslog is enabled  
# $log_syslog_facility = "mail";  

# syslog logging priority  
# type: string  
# default: "info"  
# this setting applies only when logging to syslog is enabled  
# $log_syslog_priority = "info";  

# log to plaintext file?  
# type: boolean  
# default: 0  
#$log_file = 1;  

# log filename  
# type: string  
# default: undef  
# this setting applies only when logging to file is enabled  
#$log_file_filename = "/var/log/yaa.log";  

# log to stderr?  
# type: boolean  
# default: 0  
# !!!! WARNING !!!!  
# when yaa debugging is turned on (environment variable YAA_DEBUG is set),  
# STDERR output is mapped to logger subsystem and nothing actually doesn't show up  
# on real stderr, so make shure to set up syslog or file based logging.  
# !!!! WARNING !!!!  
# $log_stderr = 0;  

# log time format when logging in file  
# type: string  
# default: "[%a, %b %e %T %Y]: "  
# see strftime(3) for more details  
# $log_time_format = undef;  


######################################################  
#               DAEMON MODE SETTINGS                 #  
######################################################  

# run as daemon?  
# type: boolean  
# default: 0, do not run as daemon  
# this setting enables daemon mode operation.  
# $daemon = 1;  

$daemon = 0;  
$daemon_lockfile = "/tmp/yaa.lock";  
$daemon_pidfile = "/tmp/yaa.pid";  
$daemon_tcpserver_loglevel = 4;  

# fork into background when running as daemon?  
# default: 1  
# this setting applies only when operating in daemon mode  
# $daemon_background = 1;  

# daemon accept lock file  
# type: string  
# default: "/var/lock/yaa.lock"  
# this setting applies only when operating in daemon mode  
# WARNING: if running in chroot jail, this option should be  
# set relative to chroot directory  
# $daemon_lockfile = "/tmp/yaa.lock";  

# daemon pid file  
# type: string  
# default: "/var/run/yaa.lock"  
# this setting applies only when operating in daemon mode  
# $daemon_pidfile = "/tmp/yaa.pid";  

# minimum number of yaa child processes  
# type: integer  
# default: 2  
# this setting applies only when operating in daemon mode  
# $daemon_min_servers = 2;  

# maximum number of yaa child processes  
# type: integer  
# default: 3  
# this setting applies only when operating in daemon mode  
# $daemon_max_servers = 3;  

# minimum number of yaa spare child processes  
# type: integer  
# default: 1  
# this setting applies only when operating in daemon mode  
# $daemon_min_spare_servers = 0;  

# maximum number of yaa spare child processes  
# type: integer  
# default: 1  
# this setting applies only when operating in daemon mode  
#$daemon_max_spare_servers = 1;  

# daemon communication protocol  
# type: string  
# protocol which your MTA uses for communication with yaa  
#  
# NOTICE: for possible values for this configuration parameter, RUN  
# yaa.pl --list-transport-protocols  
#  
# default: "SMTP"  
# this setting applies only when operating in daemon mode  
# $daemon_protocol = "LMTP";  

# tcp listen port or unix domain socket on which yaa should listen  
# type: integer/string  
# default: 40000  
# to specify unix domain socket set value to: '/path/to/socket|unix'  
#  
# see also: perldoc Net::Server::Proto  
#  
# this setting applies only when operating in daemon mode  
# $daemon_listen_port = 40000;  

# hostname which yaa should bind to.  
# type: string  
# default: "localhost"  
# this setting applies only when operating in daemon mode  
# $daemon_listen_host = "127.0.0.1";  

# daemon tcpserver (Net::Server) log level  
# type: integer  
# default: 0  
# 'O' => disable logging  
# 0 => 'err'  
# 1 => 'warning'  
# 2 => 'notice'  
# 3 => 'info'  
# 4 => 'debug'  
$daemon_tcpserver_loglevel = 4;  


######################################################  
#               YAA OBJECT SETTINGS                  #  
######################################################  

# directory used to store autoresponse message sent time database.  
# type: string  
# default: "/tmp"  
# !!!! WARNING !!!!  
#   
#   -  if you're running yaa chrooted (see configuration variable $chroot),  
#      then you need to set this variable to value RELATIVE to chroot directory  
#   
#   - directory must be writeable for uid/gid which yaa uses for message processing  
#     see also $user and $group variables  
#   
# !!!! WARNING !!!!  
# $db_dir = "/db";  

# time in seconds between to autoresponses will be sent to the  
# same message sender from message recipient which has autoresponder  
# turned on.  
#   
# !!!! WARNING !!!!  
#   
# For testing purposes, set to -1 (turn off time checking),   
# BUT DO NOT SET THIS VALUE LOWER THAN 3600 (1 hour) ON  
# PRODUCTION SYSTEM !!!!  
#   
# !!!! WARNING !!!!  
# type: integer  
# default: 7200  
# $duration_interval = 24 * 60 * 60;  
$duration_interval = "-1";  

######################################################  
#             AUTORESPONSE SETTINGS                  #  
######################################################  

# method used for sending autoresponses and forwading messages  
# type: string  
# possible values: "smtp", "sendmail"  
# - "smtp" uses smtp server to send mail  
# - "sendmail" invokes sendmail binary to send mail  
#   
# !!!!WARNING!!!!: weird things happen when using sendmail sending  
# method and running in daemon mode!  
#   
# default: "smtp"  
# $mail_sending_method = "smtp";  

# sendmail program path  
# type string  
# default: automaticaly searched in $PATH environmental variable;  
# undef if not found in $PATH.  
#$sendmail_path = undef;  

# SMTP server setting  
# type: string  
#   
# see also perldoc Net::SMTP  
#   
# default: localhost  
# $smtp_server = "localhost";  

# Use SMTP auth?  
# type: boolean  
# default: 0  
# $smtp_auth = 0;  

# SMTP auth username  
# type: string  
# default: undef  
# $smtp_username = undef;  

# SMTP auth password  
# type: string  
# default: undef  
# $smtp_password = undef;  


######################################################  
#              LOOKUP MAP SETTINGS                   #  
######################################################  

# List of ALL lookup maps  
# You need to define lookup maps here and  
# then set lookup_map_query_order, where you reference to  
# the lookup name  
#   
# NOTICE:  
# All lookup maps are initialized BEFORE Yaa! enters chroot jail (if any)  
# and BEFORE starts processing emails.  
#   
#   
# NOTICE: To obtain list of all lookup drivers, RUN  
# yaa.pl --list-lookup-map-drivers  
#   
# type: hash of hashes  
# default: empty hash (no defined lookup maps)  
$lookup_maps = {  
    #  
    # !!!WARNING!!!!  
    #  
    # FOR COMPLETE LIST OF DRIVER CONFIGURATION ARGUMENTS  
    # RUN yaa.pl --show-lookup-map-doc   
    #  
    # Lookup map configuration format  
    #   
    # 'map_name' => {  
    #    'driver' => 'DRIVER_NAME',  
    #    'driver_param1' => 'value1'.  
    #    'driver_param2' => 'value2',  
    #    'driver_param3' => 'value3',  
    # },  
    # SQL lookup map example  
    #   
    # (used sql database: mysql)  
    # (for other types see perldoc DBD::)  
    #   
     'my_sql_map' => {  
        'driver' => 'SQL',  
        'sql_dsn' => 'dbi:mysql:database=mail;host=localhost',  
        'sql_username' => "mail_admin",  
        'sql_password' => "mail_admin_password",  
        'sql_select' => "select active,message,subject,charset,forward from autoresponder where address = %m and active='1'",  
    },  
      
    # PCRE lookup map example  
    #   
    # 'my_pcre_map' => {  
    #    'driver' => 'PCRE',  
    #    'file' => "file.pcre",  
    #    'replacement_num' => 0  
    #},  
      
    # STATIC lookup map example  
    # 'my_static_map' => {  
    #    'driver' => 'STATIC',  
    #    'result_key1' => 'result_value1',  
    #    'result_key2' => 'result_value2',  
    #    'result' => 'sth'  
    #},  
      
    # LDAP lookup map sample  
    # 'my_ldap_map' => {  
    #    'driver' => 'LDAP',  
    #    'ldap_host' => 'ldap.example.org',  
    #   
    #    'ldap_bind' => 1,  
    #    'ldap_bind_dn' => "cn=Manager,dc=example,dc=org",  
    #    'ldap_bind_pw' => "secret",  
    #   
    #    'ldap_search_base' => "ou=MyOU,dc=example,dc=org",  
    #    'ldap_search_filter' => "(&(objectClass=rfc822Recipient)(mail=%m)(accountActive=1)",  
    #    'ldap_search_attrs' => ['autoResponseActive', 'autoResponseSubject', 'autoresponseMessage', 'autoResponseCharset', 'autoresponseForward'],  
    #},  
      
    # DB_File lookup map sample  
    # 'my_dbf_map' => {  
    #    'driver' => 'DB_File',  
    #    'file' => "/path/to/mydb",  
    #},  
      
    # BerkeleyDB lookup map sample  
    #'my_dbd_map' => {  
    #    'driver' => 'BerkeleyDB',  
    #    'type' => 'Btree',  
    #    'file' => "/path/to/mydb"  
    #},  
};  
  
# lookup map query order by attribute  
# for each autoresponse except 'rewrite_recipient' and 'rewrite_sender' must  
# be defined lookup query order  
#   
# Each item can be specified as:  
# + string   (example: 'domain.tld')  
#   
# OR  
#   
# lookup_map_name:result_value (example: 'my_pcre_map:result')  
#  
# Lookup map is recognized by ':' character in string.  
#   
# Lookup map 'lookup_map_name' MUST BE specified in $lookup_maps configuration  
# parameter in yaa.conf  
#   
# type: hash of hashes  
# default: empty hash (no lookups order lists defined)  
#   
#   
$lookup_map_query_order = {  
        active => [  
                'my_sql_map:active'  
        ],  
        subject => [  
                'my_sql_map:subject'  
        ],  
        message => [  
                'my_sql_map:message'  
        ],  
        charset => [  
               # 'my_sql_map:charset'  
        ],  
        forward => [  
                'my_sql_map:forward'  
        ],  
        rewrite_sender => [  
                #empty  
        ],  
        rewrite_recipient => [  
                #empty  
        ],  
        'local_domains' => [  
                'my_sql_map:local_domains'  
        ],  
};  

######################################################  
#                 OTHER SETTINGS                     #  
######################################################  

# chroot to some directory?  
# type: string  
# default: undef, do not chroot  
# Warning: yaa must be started as superuser to enable this feature.  
# this applies to daemon and single message processing mode  
# $chroot = undef;  
  
# change uid/gid before processing?  
# type: string  
# default: undef, do not change uid/gid  
# Warning: yaa must be started as superuser to enable this feature.  
# this applies to daemon and single message processing mode  
# $user = undef;  
# $group = undef;  
  
# Load additional perl modules before processing any message  
# Modules in this list will be loaded before Yaa! will process any  
# message in single process mode or become daemon, when running  
# in daemon mode.  
#   
# This configuration parameter is very handy when  
# when running in chroot jail  
#   
# type: array  
# default: empty array (don't load any additional modules)  
@extra_modules = (  
    # !!!!WARNING!!!!  
    # when as chrooted daemon, uncomment the following line  
    # 'Net::Server::Mail::ESMTP::PIPELINING',  
      
    # if running chrooted, and using mysql version  
    # of SQL lookup map, uncomment the following line  
    #'DBD::mysql',  
      
    # if running chrooted, and using postgres version  
    # of SQL lookup map, uncomment the following line  
    #'DBD::Pg',  
);  
  
######################################################  
#                 !!!!WARNING!!!!                    #  
#  COMMENT OUT THE FOLLOWING LINE TO MAKE YAA WORK!  #  
#                 !!!!WARNING!!!!                    #  
######################################################  
#die "You haven't edit configuration file, have you?:))";  
  
######################################################  
#                 !!!!WARNING!!!!                    #  
#  DO NOT REMOVE OR COMMENT OUT THE FOLLOWING LINE   #  
1;                                                   #  
###################################################### 

次に、以下を見つけて

 'my_sql_map' => {  
        'driver' => 'SQL',  
        'sql_dsn' => 'dbi:mysql:database=mail;host=localhost',  
        'sql_username' => "mail_admin",  
        'sql_password' => "mail_admin_password",  
        'sql_select' => "select active,message,subject,charset,forward from autoresponder where address = %m and active='1'", 

自分のユーザー名とパスワードに編集する必要があります。

次に、いくつかの追加データベースエントリを追加する必要があります。

INSERT INTO `forwardings` ( `source` , `destination` ) VALUES ('[email protected]', '[email protected], [email protected]');
INSERT INTO `transport` ( `domain` , `transport` ) VALUES ('autoreply.domain.com', 'yaa');
INSERT INTO `autoresponder` ( `active` , `message` , `subject` , `charset` , `forward` , `address` , `local_domains` , `tstart` , `tfinish` ) VALUES ('1', 'Message Body', 'Message Subject', '', '', '[email protected]', 'autoreply.domain.com', '0', '0');

さらに、tstart/tfinishの値を設定できます。これらはUnixタイムスタンプで行われ、特定の期間に自動応答機能を有効にすることができます。たとえば、オフィスに戻った後に自動応答機能をオフにするのを忘れる人にとって便利です。

INSERT INTO `autoresponder` ( `active` , `message` , `subject` , `charset` , `forward` , `address` , `local_domains` , `tstart` , `tfinish` ) VALUES ('1', 'Message Body', 'Message Subject', '', '', '[email protected]', 'autoreply.domain.com', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + 14400);

Thunderbirdでは、返信の件名に関して非常に奇妙な動作が見られたため、グーグルで調べて問題を修正するための小さなパッチを見つけました。

email_subject.patchというファイルを作成します:

--- Autoresponse.pm     2004-08-19 20:35:28.000000000 +0200  
+++ Autoresponse.pm     2005-07-14 13:16:03.000000000 +0200  
@@ -182,7 +182,11 @@  
        push(@headers, "Precedence: bulk");  
  
        # Subject  
-       push(@headers, "Subject: =?" . (($self->{charset}) ? $self->{charset} : $self->{default_charset}) . "?Q?" . encode_qp($subject) . "?=");  
+       #  
+       # Fixes the strange subjects that email clients don't understand  
+       # (second argument on encode_qp should be "")  
+       push(@headers, "Subject: =?" . (($self->{charset}) ? $self->{charset} : $self->{default_charset}) . "?Q?" . encode_qp($subject,"") . "?=");  
  
        push(@headers, "MIME-Version: 1.0"); 

次に、パッチを適用します:

cd /usr/local/postfix-tools/yaa-0.3/lib/
patch -p0 

このガイドは、Yaa!のデーモン化されたバージョンには関心を持っていません。これは、非常に高いメールボリュームでより効率的である可能性がありますが、デーモンバージョンが必要な場合は、yaa.confファイルを調整するだけで済むはずです。

Yaaには、特定の時間内に同じ人に返信しないなどの素晴らしい機能があり、特に2つの自動応答プログラムが互いに応答し合い、ループを作成することができるため、非常に賢いです。このようなことはYaaでは発生しません!

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。