Artigos‎ > ‎Email‎ > ‎

Comandos e Arquivos para configurar Postfix+Dovecot+Drupal+Amavis

Este passo a passo esta sem muitos comentários, mas informações adicionais estão no link http://www.howtoforge.com/drupal-plus-postfix-integration-under-ubuntu-8.04

sudo -i

Alguns pacotes que podem ser necessários (não verifiquei necessidade ainda):

amavisd-new apache2 build-essential cabextract clamav-daemon debhelper dovecot-imapd dovecot-pop3d dpatch elinks fakeroot libcdb-dev libclass-dbi-mysql-perl phpmyadmin libapache2-mod-php5 libdb-dev libgdbm-dev libldap2-dev libmysqlclient15-dev libpam-mysql libpam-smbpass libpcre3-dev libpq-dev libsasl2-2 libsasl2-modules libsasl2-modules-sql libsasl2-dev libssl-dev mutt mysql-server nomarch openssl pax php5 php5-dev php5-mysql php-pear postfix postfix-doc postfix-mysql sasl2-bin spamassassin squirrelmail squirrelmail-decode vim vim-runtime

cd /usr/src
apt-get source postfix
postconf | grep ^mail_version
wget http://vda.sourceforge.net/VDA/postfix-2.5.5-vda-ng.patch.gz
gunzip postfix-2.5.5-vda-ng.patch.gz
cd postfix-2.5.5
patch -p1 < ../postfix-2.5.5-vda-ng.patch
dpkg-buildpackage
cd ..
ls -1 *.deb
dpkg -i postfix_2.5.5-1.1_i386.deb
dpkg -i postfix-mysql_2.5.5-1.1_i386.deb
mkdir /var/www/html
mv /var/www/index.html /var/www/html/
cd /etc/apache2/sites-enabled/
ln –s ../sites-available/default 000-default
/etc/init.d/apache2 restart

cd /var/www
wget http://ftp.drupal.org/files/projects/drupal-6.x.tar.gz 
tar -xvzf drupal-6.x.tar.gz
mv drupal-6.x drupal
cd drupal
mkdir -p sites/all/modules
cd sites/all/modules
wget http://ftp.drupal.org/files/projects/mailfix-6.x-1.1.tar.gz
tar -xvzf mailfix-6.x-1.1.tar.gz
cd /var/www
chown -R www-data.www-data drupal

mysql -p
mysql> create database drupal;
mysql> grant all privileges on drupal.* to drupal @localhost identified by 'secret' with grant option;
mysql> quit

crontab -e
# Example Drupal site cron
49 * * * * /usr/bin/wget -O - -q http://www.casa.lan/cron.php &> /dev/null

cd /var/www/
mkdir -p drupal_files/
chown -R www-data.www-data drupal_files/

groupadd -g 500 vmail
useradd -g vmail -u 500 vmail -d /home/vmail -m

Criação dos arquivos abaixo sempre com o seguinte conteúdo antes:

user = drupal
password = secret
dbname = drupal
hosts = 127.0.0.1

/etc/postfix/drupal-domains.cf
query = SELECT domain_name AS domain FROM casa_mailfix_domains
WHERE domain_name = '%s'

/etc/postfix/drupal-mailboxes.cf
query = SELECT CONCAT(md.domain_name, '/', LEFT(u.mail, LOCATE('@', u.mail) - 1),'/') AS maildir
FROM casa_mailfix_domains md JOIN (casa_mailfix_users mu JOIN casa_users u
ON mu.uid = u.uid)
ON md.domain_id = mu.domain_id
WHERE u.status = 1 AND u.mail ='%s'

/etc/postfix/drupal-forward.cf
query = SELECT mu.forward
FROM casa_mailfix_users mu JOIN casa_users u
ON mu.uid = u.uid
WHERE u.mail = '%s' AND LENGTH(mu.forward) > 0

/etc/postfix/drupal-recipient-bcc.cf
query = SELECT mu.incoming_bcc
FROM casa_mailfix_users mu JOIN casa_users u
ON mu.uid = u.uid
WHERE u.status = 1 AND u.mail = '%s' AND LENGTH(mu.incoming_bcc) > 0

/etc/postfix/drupal-sender-bcc.cf
query = SELECT mu.outgoing_bcc
FROM casa_mailfix_users mu JOIN casa_users u
ON mu.uid = u.uid
WHERE u.status = 1 AND u.mail = '%s' AND LENGTH(mu.outgoing_bcc) > 0

/etc/postfix/drupal-quota.cf
query = SELECT mu.quota
FROM casa_mailfix_users mu JOIN casa_users u
ON mu.uid = u.uid
WHERE  u.mail = '%s'

este arquivo não tem o cabeçalho inicial:
/etc/pam.d/smtp
auth    required   pam_mysql.so user=drupal passwd=secret host=127.0.0.1 db=drupal table=casa_users usercolumn=mail passwdcolumn=pass crypt=0
account sufficient pam_mysql.so user=drupal passwd=secret host=127.0.0.1 db=drupal table=casa_users usercolumn=mail passwdcolumn=pass crypt=0

/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

/etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: 127.0.0.1
sql_user: drupal
sql_passwd: secret
sql_database: drupal
sql_select: SELECT pass FROM casa_users WHERE mail = '%u' AND status = 1

postconf -e 'relayhost ='
postconf -e 'relay_domains ='
postconf -e 'mynetworks = 192.168.0.0/24, 127.0.0.0/8'
postconf -e 'myhostname = master.casa.lan'
postconf -e 'mydomain = casa.lan'
postconf -e 'mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain'
postconf -e 'virtual_alias_domains ='
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/drupal-forward.cf'
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/drupal-domains.cf'
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/drupal-mailboxes.cf'
postconf -e 'virtual_mailbox_base = /home/vmail'
postconf -e 'virtual_uid_maps = static:500'
postconf -e 'virtual_gid_maps = static:500'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/master.casa.lan.pem'
postconf -e 'smtpd_tls_key_file = /etc/ssl/private/master.casa.lan.key'
postconf -e 'virtual_create_maildirsize = yes'
postconf -e 'virtual_mailbox_extended = yes'
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/drupal-quota.cf'
postconf -e 'virtual_mailbox_limit_override = yes'
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'
postconf -e 'virtual_overquota_bounce = yes'
postconf -e 'recipient_bcc_maps = proxy:mysql:/etc/postfix/drupal-recipient-bcc.cf'
postconf -e 'sender_bcc_maps = proxy:mysql:/etc/postfix/drupal-sender-bcc.cf'
postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps $recipient_bcc_maps $sender_bcc_maps'

postconf -e virtual_transport=dovecot
postconf -e dovecot_destination_recipient_limit=1
postconf -e 'content_filter = smtp-amavis:[127.0.0.1]:10024'

/etc/postfix/master.cf
pickup    fifo  n       -       -       60      1       pickup
-o content_filter=
-o receive_override_options=no_header_body_checks

dovecot   unix  -       n       n       -       -       pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}
smtp-amavis     unix    -       -       -       -       2       smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025 inet    n       -       -       -       -       smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

/etc/init.d/postfix reload

/etc/dovecot/dovecot.conf
protocols = imap imaps pop3 pop3s
mail_location = maildir:/home/vmail/%d/%n/Maildir
auth default {
mechanisms = plain login
passdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
userdb static {
args = uid=500 gid=500 home=/home/vmail/%d/%n allow_all_users=yes
}
socket listen {
master {
path = /var/run/dovecot/auth-master
mode = 0600
user = vmail
}
client {
path = /var/spool/postfix/private/auth
mode = 0600
user = postfix
group = postfix
}
}
}
protocol lda {
log_path = /home/vmail/dovecot-deliver.log
global_script_path = /home/vmail/globalsieverc
postmaster_address = postmaster@casa.lan
auth_socket_path = /var/run/dovecot/auth-master
mail_plugins = cmusieve
}
ssl_cert_file = /etc/ssl/certs/master.casa.lan.pem
ssl_key_file = /etc/ssl/private/master.casa.lan.key
ssl_disable = no
disable_plaintext_auth = no

/etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=127.0.0.1 dbname=drupal user=drupal password=secret
default_pass_scheme = PLAIN-MD5
password_query = SELECT mail AS user, pass AS password FROM casa_users WHERE mail='%u';

/etc/init.d/dovecot restart

sudo apt-get install amavisd-new spamassassin clamav-daemon
sudo apt-get install dkim-filter python-policyd-spf
sudo apt-get install pyzor razor
sudo apt-get install arj cabextract cpio lha nomarch pax rar unrar unzip zip zoo
sudo adduser clamav amavis
/etc/default/spamassassin
ENABLED=1
sudo /etc/init.d/spamassassin start

/etc/amavis/conf.d/15-content_filter_mode
use strict;
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
1;
/etc/amavis/conf.d/20-debian_defaults
final_spam_destiny = D_DISCARD;
/etc/amavis/conf.d/50-user
use strict;
$myhostname = 'master.casa.lan';
@local_domains_acl = ( "casa.lan" );
1
sudo /etc/init.d/amavis restart
whitelist no arquivo: /etc/amavis/conf.d/40-policy_banks
sudo /etc/init.d/postfix restart 
link para amavis: https://help.ubuntu.com/9.04/serverguide/C/mail-filtering.html 
Comments