INEWUP'S BLOG

CentOS_邮件服务器配置

Install Postfix to configure SMTP Server. This example shows to configure SMTP-Auth to use Dovecot's SASL function.

Configure Postfix. ( Postfix is installed by default even if you installed CentOS with Minimal.)

**# **

vi /etc/postfix/main.cf

# line 75: uncomment and specify hostname

** myhostname = **

mail.server.world

# line 83: uncomment and specify domain name

** mydomain = **

server.world

# line 99: uncomment

** myorigin = $mydomain**

# line 116: change

** inet_interfaces = **

all

# line 119: change if you use only IPv4

** inet_protocols = **

ipv4

# line 164: add

** mydestination = $myhostname, localhost.$mydomain, localhost**

, $mydomain

# line 264: uncomment and specify your LAN

** mynetworks = 127.0.0.0/8, **

10.0.0.0/24

# line 419: uncomment (use Maildir)

** home_mailbox = Maildir/**

# line 545: uncomment, line 546: add

** header_checks = regexp:/etc/postfix/header_checks**

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

** smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_client_restrictions = permit_mynetworks,reject_unknown_client,permit smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject**

**# **

vi /etc/postfix/header_checks

# add at the head

** **

# reject if email address is empty

** **

/^From:./ REJECT /^Return-Path:./ REJECT

**# **

vi /etc/postfix/body_checks

# reject if includes 'example.com' in mail body

** **

/^(|.*)example.com/ REJECT

**# **

**/etc/rc.d/init.d/postfix start **

** Starting postfix: **


**

**

chkconfig postfix on

Install Dovecot to Configure POP/IMAP Server. This example shows to configure to provide SASL function to Postfix.

**# **

yum -y install dovecot

**# **

vi /etc/dovecot/dovecot.conf

# line 31: change ( if not use IPv6 )

** listen = **


**# **

vi /etc/dovecot/conf.d/10-auth.conf

# line 9: uncomment and change ( allow plain text auth )

** disable_plaintext_auth = **

no

# line 97: add

** auth_mechanisms = plain **

login

**# **

vi /etc/dovecot/conf.d/10-mail.conf

# line 30: uncomment and add

** mail_location = **

maildir:~/Maildir

**# **

vi /etc/dovecot/conf.d/10-master.conf

# line 84-86: uncomment and add

**

Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {**

mode = 0666

** **

**user = postfix **

# add

** **

**group = postfix **

# add

** }**

**# **

**/etc/rc.d/init.d/dovecot start **

** Starting Dovecot Imap: **


**

**

chkconfig** dovecot on **

Configure for your Mail Client on your PC. This example shows with Windows Live Mail.

Start Windows Live mail and move to "Account" tab and Click "Email".

Input email address, account's password, sender's name and check a box 'Configure Manually' and go next.

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.

Click 'Finish'.

Connect and get server's folder settings automatically.

Configure SSL settings in order to encrypt datas in connection.

Create certificates first, see here.

Configure Postfix and Dovecot for SSL

**# **

vi /etc/postfix/main.cf

# add at the last line

** **

smtpd_use_tls = yes smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/certs/server.key smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache

**# **

vi /etc/postfix/master.cf

# line 17-18: uncomment

** smtps       inet   n       -       n       -       -       smtpd -o smtpd_tls_wrappermode=yes**

**# **

vi /etc/dovecot/conf.d/10-ssl.conf

# line 6: uncomment

** ssl = yes**

# line 12,13: uncomment and specify certificate

** ssl_cert =

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. This example set config as, present domain name ⇒ server.world new domain name ⇒ virtual.host and user "cent" has an email address cent@mail.server.world now and Add "UserB" newly and Give him an email address cent@mail.virtual.host

Config for Virtula Domain

**# **

vi /etc/postfix/main.cf

# add at the last line

** **

virtual_alias_domains = virtual.host virtual_alias_maps = hash:/etc/postfix/virtual

**# **

vi /etc/postfix/virtual

# add at the head

** **

cent@mail.virtual.host userB

**# **

**postmap /etc/postfix/virtual **

**

**

**/etc/rc.d/init.d/postfix reload **

** Reloading postfix: **


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.

Install Clamd and ClamSMTP

**# **

yum** --enablerepo=rpmforge -y install clamd **

**  **

# install from RPMforge

**# **

wget http://thewalter.net/stef/software/clamsmtp/clamsmtp-1.10.tar.gz

**# **

tar** zxvf clamsmtp-1.10.tar.gz **

**

**

cd** clamsmtp-1.10 **

**

**

**./configure **

**

**

**make **

**

**

**make install **

**

**

cp** ./doc/clamsmtpd.conf /etc **

**

**

cd** **

** **

**# **

vi /etc/clamsmtpd.conf

# line 11: change

** OutAddress: **

127.0.0.1:10026

# line 29: uncomment and change

** Listen: **

127.0.0.1:10025

# line 32: change

** ClamAddress: **

/var/run/clamav/clamd.sock

# line 35: uncomment

** Header: X-Virus-Scanned: ClamAV using ClamSMTP**

# line 38: uncomment

** TempDirectory: /tmp**

# line 41: uncomment

** Action: drop**

# line 50: uncomment

** User: clamav**

**# **

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**

**   && touch /var/lock/subsys/clamsmtpd**

**   return $RETVAL**

}

stop() {

**   echo -n $"Stopping ClamSmtpd: "**

**   killproc clamsmtpd**

**   RETVAL=$?**

**   echo**

**   && 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)**

**      && restart || :**

**      ;;**

**   )*

**      echo $"Usage: $0 {start|stop|status|restart}"**

**      exit 1**

esac

exit $?

** **

**# **

chmod** 755 /etc/rc.d/init.d/clamsmtp **

**

**

**/etc/rc.d/init.d/clamd start **

** Starting Clam AntiVirus Daemon: Bytecode: Security mode set to "TrustSigned".

**

**/etc/rc.d/init.d/clamsmtp start **

** Starting ClamSmtpd: **


**

**

chkconfig** --add clamsmtp **

**

**

chkconfig** clamsmtp on **

**

**

chkconfig** clamd on **

Configure Postfix

**# **

vi /etc/postfix/main.cf

# add at the last line

** **

content_filter = scan:127.0.0.1:10025

**# **

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**

** **

**# **

**/etc/rc.d/init.d/postfix restart **

** Shutting down postfix: **


** Starting postfix: **