postfix邮件服务器多域名支持配置教程详解

发布时间:2020-11-28编辑:脚本学堂
有关postfix邮件服务器支持多域名的配置方法,对postfix的虚拟域名相关选项进行设置,定义虚拟域名转换规则,更新虚拟域名规则,具体操作见文中教程。

在postfix邮件服务配置中,设置多域名支持。

两个域名 plcxue.com 和 plcxue.cn。现在 plcxue.com 作为主域名已经成功地在IP地址为 125.168.2.16 的服务器上配置了postfix。

即可以通过 abc@plcxue.com 发送和接收邮件。

希望 plcxue.cn 域名也指向该服务器,并可以通过 abc@plcxue.cn 发送和接收邮件,并且两个域名对应的用户是一致的,即发送给 abc@plcxue.com 的邮箱的用户实际上也是给 abc@plcxue.cn 邮箱的用户的邮件,而同一个用户abc可以选择使用 abc@plcxue.com 或者 abc@plcxue.cn 发送邮件,而接收方看到的是不同的域名发出来的邮件。

操作步骤:
 
一、对postfix的虚拟域名相关选项进行设置
 

$ vi /etc/postfix/main.cf
virtual_alias_maps=hash:/etc/postfix/virtual

二、定义虚拟域名转换规则
$ vi /etc/postfix/virtual //在文件末尾添加上下面两行
 

plcxue.cn anything
@plcxue.cn @plcxue.com

三、更新虚拟域名规则
 

$ postmap /etc/postfix/virtual

四、重启postfix
 

$ service postfix restart

0、准备环境
 

yum remove postfix
yum remove dovecot
yum remove sendmail
shell $> mysql -u root -p
mysql> create database postfix;

1、安装postfixadmin
 

cd /root
wget -c 'http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.2.1.1/postfixadmin-2.2.1.1.tar.gz?use_mirror=jaist'
cd /var/www
tar xvzf /home/postfixadmin-2.2.1.1.tar.gz
mv postfixadmin-2.2.1.1 postfixadmin
vi /var/www/postfixadmin/config.inc.php
$CONF['configured'] = true;
$CONF['default_language'] = 'cn';
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'root';
$CONF['database_password'] = 'your_password';
$CONF['database_name'] = 'postfix';

2、创建序列邮件操作用户和邮件目录
 

shell $> groupadd -g  1001 postfix
shell $> groupadd -g  1002 postdrop
shell $> useradd -u 1001 -g 1001 -G postdrop -d /dev/null -s /usr/sbin/nologin postfix
shell $> mkdir -p /var/vmail
shell $> chown apache:apache /var/vmail -R

3、安装postfix(带数据库插件)

3.1配置yum安装文件
 

vi /etc/yum.repos.d/centos-Base.repo
[base]
exclude=postfix
[update]
exclude=postfix
[centosplus]
enabled=1
includepkgs=postfix
yum install postfix
chkconfig postfix on

3.2、配置postfix设置
 

vi /etc/postfix/mysql-domains.cf
host = localhost
user = root
password = your_password
dbname = postfix
table = domain
select_field = domain
where_field = domain
vi /etc/postfix/mysql-users.cf
host = localhost
user = root
password = your_password
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
vi /etc/postfix/mysql-aliases.cf
host = localhost
user = root
password = your_password
dbname = postfix
table = alias
select_field = goto
where_field = address

3.3,记录下来apche的gid,用于替换main.cf和dovecot.conf里的对应项目(在本文中是48)
cat /etc/group可以看到apache的gid

3.4,配置main.cf
 

vi /etc/postfix/main.cf
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
####################################################################
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
mydestination =
mynetworks = 127.0.0.0/8
inet_interfaces = all
home_mailbox = Maildir/
####################################################################
virtual_gid_maps = static:48         
virtual_mailbox_base = /var/vmail             ###虚拟用户目录
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf
virtual_minimum_uid = 48                          ### 给 apache 权限。
virtual_transport = virtual
virtual_uid_maps = static:48
##########################################
message_size_limit = 52428800
mailbox_size_limit = 209715200
virtual_mailbox_limit = 209715200
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_override = yes
virtual_overquota_bounce = yes
#########################################
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot               ###定义安装方式  dovecot
smtpd_sasl_path = private/auth-client    #####  路径要与 dovecot 一样,一会要讲到
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,
                                permit_sasl_authenticated,
                                reject_invalid_hostname,
                                reject_non_fqdn_hostname,
                                reject_unknown_sender_domain,
                                reject_non_fqdn_sender,
                                reject_non_fqdn_recipient,
                                reject_unknown_recipient_domain,
                                reject_unauth_pipelining,
                                reject_unauth_destination
service postfix restart

4、安装dovecot
 

yum install dovecot

vi /etc/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=root password=you_password
default_pass_scheme = MD5-CRYPT
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 48 AS uid, 48 AS gid FROM mailbox WHERE username = '%u'

vi /etc/dovecot.conf
base_dir = /var/run/dovecot/
protocols = pop3 pop3s
listen = *
disable_plaintext_auth = no
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot.info
log_timestamp = "%Y-%m-%d %H:%M:%S "
ssl_disable = yes
mail_location = maildir:/var/vmail/%u
mail_privileged_group = mail
first_valid_uid = 48
protocol imap {
}
protocol pop3 {
      pop3_uidl_format = XuXv
}
auth default {
    mechanisms = plain login
   passdb pam {
  }
  passdb sql {
    args = /etc/dovecot-mysql.conf
  }
  userdb passwd {
  }
  userdb sql {
    args = /etc/dovecot-mysql.conf
  }
  user = root
  socket listen {
    client {
      path = /var/spool/postfix/private/auth-client  #这里对应 postfix smtpd_sasl_path 
      mode = 0660
        user = postfix
        group = postfix
    }
  }
}

dict {
}
plugin {
}

设置dovecot自启动:
 

chkconfig dovecot on
service dovecot start