CentOS_邮件服务器配置
Install Postfix to configure SMTP Server. This example shows to configure SMTP-Auth to use Dovecot's SASL function. |
|
[1] |
Configure Postfix. ( Postfix is installed by default even if you installed CentOS with Minimal.) |
[root@mail ~]# vi /etc/postfix/main.cf # line 75: uncomment and specify hostname
mail.server.world # line 83: uncomment and specify domain name
server.world # line 99: uncomment
# line 116: change
all # line 119: change if you use only IPv4
ipv4 # line 164: add
, $mydomain # line 264: uncomment and specify your LAN
10.0.0.0/24 # line 419: uncomment (use Maildir)
# line 545: uncomment, line 546: add
body_checks = regexp:/etc/postfix/body_checks # line 571: add
smtpd_banner = $myhostname ESMTP # add at the last line
# limit an email size 10M
message_size_limit = 10485760
# limit mailbox 1G
mailbox_size_limit = 1073741824 # for SMTP-Auth settings
[root@mail ~]# vi /etc/postfix/header_checks # add at the head
# reject if email address is empty
/^From:.*<#.*@.*>/ REJECT [root@mail ~]# vi /etc/postfix/body_checks # reject if includes 'example.com' in mail body
/^(|[^>].*)example.com/ REJECT [root@mail ~]# /etc/rc.d/init.d/postfix start
[ OK ]
chkconfig postfix on |
Install Dovecot to Configure POP/IMAP Server. This example shows to configure to provide SASL function to Postfix. |
[root@mail ~]# yum -y install dovecot [root@mail ~]# vi /etc/dovecot/dovecot.conf # line 31: change ( if not use IPv6 )
* [root@mail ~]# vi /etc/dovecot/conf.d/10-auth.conf # line 9: uncomment and change ( allow plain text auth )
no # line 97: add
login [root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf # line 30: uncomment and add
maildir:~/Maildir [root@mail ~]# vi /etc/dovecot/conf.d/10-master.conf # line 84-86: uncomment and add
mode = 0666
user = postfix # add
group = postfix # add
[root@mail ~]# /etc/rc.d/init.d/dovecot start
[ OK ]
chkconfig dovecot on |
|
Configure for your Mail Client on your PC. This example shows with Windows Live Mail. |
|
[1] |
Start Windows Live mail and move to "Account" tab and Click "Email". |
[2] |
Input email address, account's password, sender's name and check a box 'Configure Manually' and go next. |
[3] |
Select IMAP or POP. This example selects IMAP. And input other information of your Mail server. Don't forget to check a box 'this server requires to authenticate' at the bottom. |
[4] |
Click 'Finish'. |
[5] |
Connect and get server's folder settings automatically. |
Configure SSL settings in order to encrypt datas in connection. |
|
[1] |
|
[2] |
Configure Postfix and Dovecot for SSL |
[root@mail ~]# vi /etc/postfix/main.cf # add at the last line
smtpd_use_tls = yes [root@mail ~]# vi /etc/postfix/master.cf # line 17-18: uncomment
[root@mail ~]# vi /etc/dovecot/conf.d/10-ssl.conf # line 6: uncomment
# line 12,13: uncomment and specify certificate
/etc/pki/tls/certs/server.crt
/etc/pki/tls/certs/server.key [root@mail ~]# /etc/rc.d/init.d/postfix restart
[ OK ]
[ OK ]
/etc/rc.d/init.d/dovecot restart
[ OK ]
[ OK ] |
Configure on client. Change settings like following example. (if you use PO3S, input '995 for incoming mail) |
Click syncronize on Windows Live Mail, then following warning is shown because certificate file is created on your server. It's no ploblem. Click 'Yes' to Proceed, then it's possible to send/receive emails trough SSL connection. |
Configure for Virtulal Domain to send an email with another domain name different from original domain. |
|
[1] |
Config for Virtula Domain |
[root@mail ~]# vi /etc/postfix/main.cf # add at the last line
virtual_alias_domains = virtual.host [root@mail ~]# vi /etc/postfix/virtual # add at the head
cent@mail.virtual.host userB [root@mail ~]# postmap /etc/postfix/virtual
/etc/rc.d/init.d/postfix reload
[ OK ] |
[2] |
Configure on client for new account and make sure to be able to send emails. |
Install Clamav first and Configure to run Postfix with Clamav to scan virus timely. Install ClamSMTP to do it. |
|
[1] |
Install Clamd and ClamSMTP |
[root@mail ~]# yum --enablerepo=rpmforge -y install clamd
# install from RPMforge [root@mail ~]# wget http://thewalter.net/stef/software/clamsmtp/clamsmtp-1.10.tar.gz [root@mail ~]# tar zxvf clamsmtp-1.10.tar.gz
cd clamsmtp-1.10
./configure
make
make install
cp ./doc/clamsmtpd.conf /etc
[root@mail ~]# vi /etc/clamsmtpd.conf # line 11: change
127.0.0.1:10026 # line 29: uncomment and change
127.0.0.1:10025 # line 32: change
/var/run/clamav/clamd.sock # line 35: uncomment
# line 38: uncomment
# line 41: uncomment
# line 50: uncomment
[root@mail ~]# vi /etc/rc.d/init.d/clamsmtp # create init script #!/bin/bash
# clamsmtpd: Start/Stop clamsmtpd # # chkconfig: - 65 40 # description: Clamsmtpd is smtpd for Clamav Antivirus daemon. # # processname: clamsmtpd # pidfile: /var/run/clamav/clamsmtpd.pid
. /etc/rc.d/init.d/functions . /etc/sysconfig/network
CONFIG_FILE=/etc/clamsmtpd.conf PID_DIR=/var/run/clamav
RETVAL=0 start() { echo -n $"Starting ClamSmtpd: " daemon /usr/local/sbin/clamsmtpd -f $CONFIG_FILE -p $PID_DIR/clamsmtpd.pid RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamsmtpd return $RETVAL } stop() { echo -n $"Stopping ClamSmtpd: " killproc clamsmtpd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/run/clamsmtp/clamsmtpd.pid /var/lock/subsys/clamsmtpd return $RETVAL } case "$1" in start) start ;; stop) stop ;; status) status clamsmtpd ;; restart) stop start ;; condrestart) [ -f /var/lock/subsys/clamsmtpd ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac exit $?
[root@mail ~]# chmod 755 /etc/rc.d/init.d/clamsmtp
/etc/rc.d/init.d/clamd start
/etc/rc.d/init.d/clamsmtp start
[ OK ]
chkconfig --add clamsmtp
chkconfig clamsmtp on
chkconfig clamd on |
[2] |
Configure Postfix |
[root@mail ~]# vi /etc/postfix/main.cf # add at the last line
content_filter = scan:127.0.0.1:10025 [root@mail ~]# vi /etc/postfix/master.cf # add at the last line
scan unix - - n - 16 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes 127.0.0.1:10026 inet n - n - 16 smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks_style=host -o smtpd_authorized_xforward_hosts=127.0.0.0/8
[root@mail ~]# /etc/rc.d/init.d/postfix restart
[ OK ]
[ OK ] |