A-A+

CentOS_邮件服务器配置

2013年02月28日 Linux运维 评论 67 条 阅读 4,498 次

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


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

[root@mail ~]# 

vi /etc/postfix/header_checks

# add at the head

 

# reject if email address is empty

 

/^From:.*<#.*@.*>/ REJECT
/^Return-Path:.*<#.*@.*>/ 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 


Starting postfix: 

[  OK  ]


[root@mail ~]# 

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 )


listen = 

*

[root@mail ~]# 

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

[root@mail ~]# 

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

# line 30: uncomment and add


mail_location = 

maildir:~/Maildir

[root@mail ~]# 

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


}

[root@mail ~]# 

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


Starting Dovecot Imap: 

[  OK  ]


[root@mail ~]# 

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]

Create certificates first, see here.

[2]

Configure Postfix and Dovecot for SSL

[root@mail ~]# 

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

[root@mail ~]# 

vi /etc/postfix/master.cf

# line 17-18: uncomment


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

[root@mail ~]# 

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

# line 6: uncomment


ssl = yes

# line 12,13: uncomment and specify certificate


ssl_cert = <

/etc/pki/tls/certs/server.crt


ssl_key = <

/etc/pki/tls/certs/server.key

[root@mail ~]# 

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


Shutting down postfix: 

[ OK ]


Starting postfix: 

[ OK ]


[root@mail ~]# 

/etc/rc.d/init.d/dovecot restart 


Stopping Dovecot Imap: 

[ OK ]


Starting Dovecot Imap: 

[ 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.
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

[1]

Config for Virtula Domain

[root@mail ~]# 

vi /etc/postfix/main.cf

# add at the last line

 

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

[root@mail ~]# 

vi /etc/postfix/virtual

# add at the head

 

cent@mail.virtual.host userB

[root@mail ~]# 

postmap /etc/postfix/virtual 


[root@mail ~]# 

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


Reloading postfix: 

[ 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 


[root@mail ~]# 

cd clamsmtp-1.10 


[root@mail clamsmtp-1.10]# 

./configure 


[root@mail clamsmtp-1.10]# 

make 


[root@mail clamsmtp-1.10]# 

make install 


[root@mail clamsmtp-1.10]# 

cp ./doc/clamsmtpd.conf /etc 


[root@mail clamsmtp-1.10]# 

cd 

 

[root@mail ~]# 

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

[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 


[root@mail ~]# 

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


Starting Clam AntiVirus Daemon: Bytecode: Security mode set to "TrustSigned".
[ OK ]
[root@mail ~]# 

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


Starting ClamSmtpd: 

[ OK ]


[root@mail ~]# 

chkconfig --add clamsmtp 


[root@mail ~]# 

chkconfig clamsmtp on 


[root@mail ~]# 

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 


Shutting down postfix: 

[ OK ]


Starting postfix: 

[ OK ]

给我留言