#####################
###邮件服务搭建与配置####
#####################
本文是Postfix+Dovecot+Mysql搭建邮件服务器
postfix(作为发送邮件服务器)+dovecot(作为接收邮件服务器)+mysql(作为数据库)
接下来的实验会有两个邮件服务主机:
mailwestos.westos.com 172.25.254.112
maillinux.linux.com 172.25.254.212
两个主机之间的交互通过 DNS 服务配置的邮件域名解析
DNS服务器被装在了 172.25.254.112 (mailwestos.westos.com) 上
Postfix服务: 提供SMTP协议,监听25端口
Dovecot服务:提供pop3协议,监听110端口
用户1给用户2发邮件:
用户1通过25端口(SMTP协议)将邮件发给主机
用户2登陆邮箱,通过110端口(pop3协议)从主机中读取邮件
用户可以通过25端口进行远程邮件发送
但是远程邮件的接收要通过110端口
110端口由pop3协议监听
dovecot服务提供pop3协议
所以,一个完整的邮件主机(用户能接收并发送邮件)必须具备两个服务:SMTP以及DOVECOT
不同主机之间的邮件交换必须通过DNS邮件域名解析
一个邮件主机上的用户可以是实体用户(服务器上真实存在的用户,下文中的root和student)
也可以是虚拟用户(每个用户的信息存在数据库中,这也是现在企业所提供的邮件服务方式)
下面就是具体配置:
===================
关于 DNS 的配置:
===================
服务端:ip:(mailwestos.westos.com)
yum install bind -y
vim /etc/named.conf
-----------
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
.
.
.
dnssec-validation no;
.
.
------------
vim /etc/named.rfc1912.zones
----------
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
};
---------
cd /var/named
ls
cp -p named.localhost westos.com.zone
vim westos.com.zone
cp -p westos.com.zone linux.com.zone
vim linux.com.zone
systemctl restart named
systemctl stop firewalld.service
-------------------------------------------------
[root@mailwestos named]# cat westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.112
westos.com. MX 1 172.25.254.112.
********************************************************
[root@mailwestos named]# cat linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.112
linux.com. MX 1 172.25.254.212.
----------------------------------------------------
测试端:ip:(maillinux.linux.com)
vim /etc/resolv.conf
---------------
nameserver 172.25.254.112
--------------
dig -t mx linux.com
dig -t mx westos.com
**********************************************
邮件收发之间没有关系
dovecot 收件服务 提供pop等协议 用户验证
**********************************************
==========
邮件发送:
==========
1>更改配置文件 开启25服务器接收端口
vim /etc/postfix/main.cf
-------------------------------
76 myhostname = mailwestos.westos.com
83 mydomain = westos.com
99 myorigin = $mydomain ##重写本地发布的电子邮件,使其显示为来自该域,确保响应返回入站邮件服务器
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
--------------------------------
systemctl restart postfix.service
mailq ##查看退回的邮件
postqueue -f ##刷新邮箱队列
mail ##查看邮箱/mysq
mail root@linux.com ##给 root@linux.com 发送邮件
2>邮件用户别名:
vim /etc/aliases
---------
admin: root
---------
root的别名
postalias /etc/aliases
在本机上进行更改后
别的主机上 发送邮件时用这个别名主机也能接受到
3>邮件群发:
在 maillinux.linux.com 上:
vim /etc/aliases
---------
qun: :include:/etc/postfix/users
---------
postalias /etc/aliases
vim /etc/postfix/users
----------
root
student
----------
测试:
在 mailwestos.westos.com 上:
[root@maillinux ~]# mail qun@westos.com
Subject: ttttttttttt
dsadsa
.
EOT
[root@maillinux ~]# mailq
Mail queue is empty
在 maillinux.linux.com 的 student 用户上:
[student@maillinux ~]$ mail qun@linux.com
Subject: dddddd
dsa
sa
.
EOT
[student@maillinux ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? foR help.
"/var/spool/mail/student": 2 messages 2 new
>N 1 root Tue Mar 14 06:35 24/853 "taaaaaaaaaa"
N 2 Student User Tue Mar 14 06:42 22/668 "dddddd"
& q
这个群发只能发给有这个配置的主机上
4>邮件地址伪装:
入站地址伪装:
vim /etc/postfix/virtual
---------------
admin@qq.com root@linux.com ##全部伪装
@qq.com @linux.com ##仅对域名伪装
---------------
postmap /etc/postfix/virtual ##对文件加密
cd /etc/postfix/
ls
postconf -d | grep virtual
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
systemctl restart postfix.service
出站地址伪装:
别人读取到你的地址为你伪装的地址
vim /etc/postfix/generic
----------------
root@linux.com root@qq.com
----------------
把自己的地址伪装成 root@qq.com
postmap generic
postconf -d | grep generic
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
systemctl restart postfix.service
mail root@westos.com ##发给westos之后 邮件显示发送人为 root@qq.com
5>远程邮件发送(检测邮件发送服务配置是否成功):
在一台用户机上(不是上面两台主机)连接212给112发送邮件:
yum install telnet -y
systemctl restart telnet
telnet 172.25.254.212 25 ##连接212 的 25 端口 (25端口为邮件发送端口)
[root@mailwestos named]# telnet 172.25.254.212 25
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
220 miallinux.linux.com ESMTP Postfix
mail from:root@qq.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
djsakf
anlkf
csa
cdnlksa
.
250 2.0.0 Ok: queued as 60029247563
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
==========
邮件接受:
==========
1>接收服务的安装与端口开启
yum install dovecot ##提供邮件接收端口(110 143 993 995)pop3、imap协议
vim /etc/dovecot/dovecot.conf
--------------
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
--------------
vim /etc/dovecot/conf.d/10-mail.conf
------------
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
--------------
systemctl restart dovecot
开启邮件接收端口(110 143 993 995)
pop3 110
pop3s 995
imap 143
imaps 993
2>远程邮件接收(检测端口有没有开启):
yum install mutt -y
mutt -f pop://student@172.25.254.212 ##只能查看普通用户的 必须开启邮件接受端口
##172.25.254.212 下的 student
[student@maillinux ~]$ mkdir mail/.imap -p
[student@maillinux ~]$ touch mail/.imap/INBOX
为使所有的新用户都默认建立这个文件 在root下 /etc/skel/
mkdir mail/.imap -p
mail/.imap/INBOX
3>虚拟邮箱账户(mysql+dovecot+postfix)
mysql数据库配置:
yum install mariadb-server.x86_64 httpd php php-mysql -y ##安装数据库 php等基本配置
systemctl start mariadb
vim /etc/my.cnf ##添加以下内容
-----------
skip-networking=1 ##关闭数据库端口
----------
mysql_secure_installation ##设定数据库密码
cd /var/www/html/
scp kiosk@172.25.254.12:/home/kiosk/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 . ##拷贝一个数据库插件,以在浏览器上对数据库进行操作
ls
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages mysqladmin
rm -fr *.bz2
ls
cd mysqladmin/
ls
cp config.sample.inc.php config.inc.php
vim config.inc.php ##里面引号里的内容可以随便填写
systemctl restart mariadb
systemctl restart httpd
mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##创建用户
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##给用户授权
数据库信息:
数据库:email 表:mailuser
##编辑以下文件 使数据库与postfix连接
[root@maillinux postfix]# cat /etc/postfix/mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = username
where_field = username
[root@maillinux postfix]# cat /etc/postfix/mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = domain
where_field = domain
[root@maillinux postfix]# cat /etc/postfix/mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = maildir
where_field = username
##检测数据库与postfix连接成功与否
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.com/admin
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-user.cf
admin
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
##所有用户都使用vmail的身份,将他们家目录分开
groupadd -g 888 vmail
useradd -u 888 -g 888 vmail
cd /home/vmail/
postconf -d | grep virtual
postconf -e "virtual_mailbox_base = /home/vmail"
ll /home/vmail
postconf -e "virtual_gid_maps = static:888"
postconf -e "virtual_uid_maps = static:888"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
ll /etc/postfix/mysql-user.cf
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
ll /etc/postfix/mysql-mailbox.cf
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
ll /etc/postfix/mysql-domain.cf
[root@maillinux vmail]# tail -8 /etc/postfix/main.cf
#
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf
virtual_mailbox_base = /home/vmail
virtual_gid_maps = static:888
virtual_uid_maps = static:888
virtual_mailbox_maps = /etc/postfix/mysql-mailbox.cf
virtual_mailbox_domains = /etc/postfix/mysql-domain.cf
systemctl restart postfix.service
mail admin@redhat.com ##检测数据库里的虚拟用户能否使用
mailq
postqueue -f
mailq
cd /home/vmail/redhat.com/admin/new
cat 1489224408.Vfd01I27121cM454797.maillinux.linux.com
远程收件:(dovecot+mysql)
yum install dovecot-mysql -y
vim /etc/dovecot/dovecot.conf
---------------------------
48 login_trusted_networks = 0.0.0.0/0 ##允许访问地址网络
49 disable_plaintext_auth = no ##开启铭文认证
--------------------------
vim /etc/dovecot/conf.d/10-auth.conf
------------------
123 !include auth-sql.conf.ext ##开启数据库认证
------------------
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
vim dovecot-sql.conf.ext ##此文件里的诸多配置以自己建立的数据库信息为准
--------------------
32 driver = mysql
71 connect = host=localhost dbname=emial user=postfix password=postfix ##填写的是自己使用的数据库的信息
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM emailluser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE usrname = '%u'
----------------------
vim conf.d/10-mail.conf
----------
30 mail_location = maildir:/home/vmail/%d/%n ##用户家目录配置
----------
[root@maillinux dovecot]# systemctl restart dovecot
[root@maillinux dovecot]# telnet 172.25.254.212 110 ##检测mysql+dovecot配置有没有错
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user admin@redhat.com
+OK
pass 123
+OK Logged in.
quit
雷鸟服务端安装:
在其他机器上安装雷鸟(远程控制邮件接发的图形软件)
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
thunderbird
接下来的实验会有两个邮件服务主机:
mailwestos.westos.com 172.25.254.112
maillinux.linux.com 172.25.254.212
两个主机之间的交互通过 DNS 服务配置的邮件域名解析
DNS服务器被装在了 172.25.254.112 (mailwestos.westos.com) 上
Postfix服务: 提供SMTP协议,监听25端口
Dovecot服务:提供pop3协议,监听110端口
用户1给用户2发邮件:
用户1通过25端口(SMTP协议)将邮件发给主机
用户2登陆邮箱,通过110端口(pop3协议)从主机中读取邮件
用户可以通过25端口进行远程邮件发送
但是远程邮件的接收要通过110端口
110端口由pop3协议监听
dovecot服务提供pop3协议
所以,一个完整的邮件主机(用户能接收并发送邮件)必须具备两个服务:SMTP以及DOVECOT
不同主机之间的邮件交换必须通过DNS邮件域名解析
一个邮件主机上的用户可以是实体用户(服务器上真实存在的用户,下文中的root和student)
也可以是虚拟用户(每个用户的信息存在数据库中,这也是现在企业所提供的邮件服务方式)
下面就是具体配置:
===================
关于 DNS 的配置:
===================
服务端:ip:(mailwestos.westos.com)
yum install bind -y
vim /etc/named.conf
-----------
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
.
.
.
dnssec-validation no;
.
.
------------
vim /etc/named.rfc1912.zones
----------
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
};
---------
cd /var/named
ls
cp -p named.localhost westos.com.zone
vim westos.com.zone
cp -p westos.com.zone linux.com.zone
vim linux.com.zone
systemctl restart named
systemctl stop firewalld.service
-------------------------------------------------
[root@mailwestos named]# cat westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.112
westos.com. MX 1 172.25.254.112.
********************************************************
[root@mailwestos named]# cat linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.112
linux.com. MX 1 172.25.254.212.
----------------------------------------------------
测试端:ip:(maillinux.linux.com)
vim /etc/resolv.conf
---------------
nameserver 172.25.254.112
--------------
dig -t mx linux.com
dig -t mx westos.com
**********************************************
邮件收发之间没有关系
dovecot 收件服务 提供pop等协议 用户验证
**********************************************
==========
邮件发送:
==========
1>更改配置文件 开启25服务器接收端口
vim /etc/postfix/main.cf
-------------------------------
76 myhostname = mailwestos.westos.com
83 mydomain = westos.com
99 myorigin = $mydomain ##重写本地发布的电子邮件,使其显示为来自该域,确保响应返回入站邮件服务器
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
--------------------------------
systemctl restart postfix.service
mailq ##查看退回的邮件
postqueue -f ##刷新邮箱队列
mail ##查看邮箱/mysq
mail root@linux.com ##给 root@linux.com 发送邮件
2>邮件用户别名:
vim /etc/aliases
---------
admin: root
---------
root的别名
postalias /etc/aliases
在本机上进行更改后
别的主机上 发送邮件时用这个别名主机也能接受到
3>邮件群发:
在 maillinux.linux.com 上:
vim /etc/aliases
---------
qun: :include:/etc/postfix/users
---------
postalias /etc/aliases
vim /etc/postfix/users
----------
root
student
----------
测试:
在 mailwestos.westos.com 上:
[root@maillinux ~]# mail qun@westos.com
Subject: ttttttttttt
dsadsa
.
EOT
[root@maillinux ~]# mailq
Mail queue is empty
在 maillinux.linux.com 的 student 用户上:
[student@maillinux ~]$ mail qun@linux.com
Subject: dddddd
dsa
sa
.
EOT
[student@maillinux ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? foR help.
"/var/spool/mail/student": 2 messages 2 new
>N 1 root Tue Mar 14 06:35 24/853 "taaaaaaaaaa"
N 2 Student User Tue Mar 14 06:42 22/668 "dddddd"
& q
这个群发只能发给有这个配置的主机上
4>邮件地址伪装:
入站地址伪装:
vim /etc/postfix/virtual
---------------
admin@qq.com root@linux.com ##全部伪装
@qq.com @linux.com ##仅对域名伪装
---------------
postmap /etc/postfix/virtual ##对文件加密
cd /etc/postfix/
ls
postconf -d | grep virtual
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
systemctl restart postfix.service
出站地址伪装:
别人读取到你的地址为你伪装的地址
vim /etc/postfix/generic
----------------
root@linux.com root@qq.com
----------------
把自己的地址伪装成 root@qq.com
postmap generic
postconf -d | grep generic
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
systemctl restart postfix.service
mail root@westos.com ##发给westos之后 邮件显示发送人为 root@qq.com
5>远程邮件发送(检测邮件发送服务配置是否成功):
在一台用户机上(不是上面两台主机)连接212给112发送邮件:
yum install telnet -y
systemctl restart telnet
telnet 172.25.254.212 25 ##连接212 的 25 端口 (25端口为邮件发送端口)
[root@mailwestos named]# telnet 172.25.254.212 25
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
220 miallinux.linux.com ESMTP Postfix
mail from:root@qq.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
djsakf
anlkf
csa
cdnlksa
.
250 2.0.0 Ok: queued as 60029247563
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
==========
邮件接受:
==========
1>接收服务的安装与端口开启
yum install dovecot ##提供邮件接收端口(110 143 993 995)pop3、imap协议
vim /etc/dovecot/dovecot.conf
--------------
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
--------------
vim /etc/dovecot/conf.d/10-mail.conf
------------
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
--------------
systemctl restart dovecot
开启邮件接收端口(110 143 993 995)
pop3 110
pop3s 995
imap 143
imaps 993
2>远程邮件接收(检测端口有没有开启):
yum install mutt -y
mutt -f pop://student@172.25.254.212 ##只能查看普通用户的 必须开启邮件接受端口
##172.25.254.212 下的 student
[student@maillinux ~]$ mkdir mail/.imap -p
[student@maillinux ~]$ touch mail/.imap/INBOX
为使所有的新用户都默认建立这个文件 在root下 /etc/skel/
mkdir mail/.imap -p
mail/.imap/INBOX
3>虚拟邮箱账户(mysql+dovecot+postfix)
mysql数据库配置:
yum install mariadb-server.x86_64 httpd php php-mysql -y ##安装数据库 php等基本配置
systemctl start mariadb
vim /etc/my.cnf ##添加以下内容
-----------
skip-networking=1 ##关闭数据库端口
----------
mysql_secure_installation ##设定数据库密码
cd /var/www/html/
scp kiosk@172.25.254.12:/home/kiosk/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 . ##拷贝一个数据库插件,以在浏览器上对数据库进行操作
ls
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages mysqladmin
rm -fr *.bz2
ls
cd mysqladmin/
ls
cp config.sample.inc.php config.inc.php
vim config.inc.php ##里面引号里的内容可以随便填写
systemctl restart mariadb
systemctl restart httpd
mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##创建用户
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##给用户授权
数据库信息:
数据库:email 表:mailuser
##编辑以下文件 使数据库与postfix连接
[root@maillinux postfix]# cat /etc/postfix/mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = username
where_field = username
[root@maillinux postfix]# cat /etc/postfix/mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = domain
where_field = domain
[root@maillinux postfix]# cat /etc/postfix/mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = maildir
where_field = username
##检测数据库与postfix连接成功与否
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.com/admin
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-user.cf
admin
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
##所有用户都使用vmail的身份,将他们家目录分开
groupadd -g 888 vmail
useradd -u 888 -g 888 vmail
cd /home/vmail/
postconf -d | grep virtual
postconf -e "virtual_mailbox_base = /home/vmail"
ll /home/vmail
postconf -e "virtual_gid_maps = static:888"
postconf -e "virtual_uid_maps = static:888"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
ll /etc/postfix/mysql-user.cf
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
ll /etc/postfix/mysql-mailbox.cf
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
ll /etc/postfix/mysql-domain.cf
[root@maillinux vmail]# tail -8 /etc/postfix/main.cf
#
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf
virtual_mailbox_base = /home/vmail
virtual_gid_maps = static:888
virtual_uid_maps = static:888
virtual_mailbox_maps = /etc/postfix/mysql-mailbox.cf
virtual_mailbox_domains = /etc/postfix/mysql-domain.cf
systemctl restart postfix.service
mail admin@redhat.com ##检测数据库里的虚拟用户能否使用
mailq
postqueue -f
mailq
cd /home/vmail/redhat.com/admin/new
cat 1489224408.Vfd01I27121cM454797.maillinux.linux.com
远程收件:(dovecot+mysql)
yum install dovecot-mysql -y
vim /etc/dovecot/dovecot.conf
---------------------------
48 login_trusted_networks = 0.0.0.0/0 ##允许访问地址网络
49 disable_plaintext_auth = no ##开启铭文认证
--------------------------
vim /etc/dovecot/conf.d/10-auth.conf
------------------
123 !include auth-sql.conf.ext ##开启数据库认证
------------------
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
vim dovecot-sql.conf.ext ##此文件里的诸多配置以自己建立的数据库信息为准
--------------------
32 driver = mysql
71 connect = host=localhost dbname=emial user=postfix password=postfix ##填写的是自己使用的数据库的信息
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM emailluser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE usrname = '%u'
----------------------
vim conf.d/10-mail.conf
----------
30 mail_location = maildir:/home/vmail/%d/%n ##用户家目录配置
----------
[root@maillinux dovecot]# systemctl restart dovecot
[root@maillinux dovecot]# telnet 172.25.254.212 110 ##检测mysql+dovecot配置有没有错
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user admin@redhat.com
+OK
pass 123
+OK Logged in.
quit
雷鸟服务端安装:
在其他机器上安装雷鸟(远程控制邮件接发的图形软件)
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
thunderbird
###邮件服务搭建与配置####
#####################
本文是Postfix+Dovecot+Mysql搭建邮件服务器
postfix(作为发送邮件服务器)+dovecot(作为接收邮件服务器)+mysql(作为数据库)
接下来的实验会有两个邮件服务主机:
mailwestos.westos.com 172.25.254.112
maillinux.linux.com 172.25.254.212
两个主机之间的交互通过 DNS 服务配置的邮件域名解析
DNS服务器被装在了 172.25.254.112 (mailwestos.westos.com) 上
Postfix服务: 提供SMTP协议,监听25端口
Dovecot服务:提供pop3协议,监听110端口
用户1给用户2发邮件:
用户1通过25端口(SMTP协议)将邮件发给主机
用户2登陆邮箱,通过110端口(pop3协议)从主机中读取邮件
用户可以通过25端口进行远程邮件发送
但是远程邮件的接收要通过110端口
110端口由pop3协议监听
dovecot服务提供pop3协议
所以,一个完整的邮件主机(用户能接收并发送邮件)必须具备两个服务:SMTP以及DOVECOT
不同主机之间的邮件交换必须通过DNS邮件域名解析
一个邮件主机上的用户可以是实体用户(服务器上真实存在的用户,下文中的root和student)
也可以是虚拟用户(每个用户的信息存在数据库中,这也是现在企业所提供的邮件服务方式)
下面就是具体配置:
===================
关于 DNS 的配置:
===================
服务端:ip:(mailwestos.westos.com)
yum install bind -y
vim /etc/named.conf
-----------
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
.
.
.
dnssec-validation no;
.
.
------------
vim /etc/named.rfc1912.zones
----------
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
};
---------
cd /var/named
ls
cp -p named.localhost westos.com.zone
vim westos.com.zone
cp -p westos.com.zone linux.com.zone
vim linux.com.zone
systemctl restart named
systemctl stop firewalld.service
-------------------------------------------------
[root@mailwestos named]# cat westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.112
westos.com. MX 1 172.25.254.112.
********************************************************
[root@mailwestos named]# cat linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.112
linux.com. MX 1 172.25.254.212.
----------------------------------------------------
测试端:ip:(maillinux.linux.com)
vim /etc/resolv.conf
---------------
nameserver 172.25.254.112
--------------
dig -t mx linux.com
dig -t mx westos.com
**********************************************
邮件收发之间没有关系
dovecot 收件服务 提供pop等协议 用户验证
**********************************************
==========
邮件发送:
==========
1>更改配置文件 开启25服务器接收端口
vim /etc/postfix/main.cf
-------------------------------
76 myhostname = mailwestos.westos.com
83 mydomain = westos.com
99 myorigin = $mydomain ##重写本地发布的电子邮件,使其显示为来自该域,确保响应返回入站邮件服务器
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
--------------------------------
systemctl restart postfix.service
mailq ##查看退回的邮件
postqueue -f ##刷新邮箱队列
mail ##查看邮箱/mysq
mail root@linux.com ##给 root@linux.com 发送邮件
2>邮件用户别名:
vim /etc/aliases
---------
admin: root
---------
root的别名
postalias /etc/aliases
在本机上进行更改后
别的主机上 发送邮件时用这个别名主机也能接受到
3>邮件群发:
在 maillinux.linux.com 上:
vim /etc/aliases
---------
qun: :include:/etc/postfix/users
---------
postalias /etc/aliases
vim /etc/postfix/users
----------
root
student
----------
测试:
在 mailwestos.westos.com 上:
[root@maillinux ~]# mail qun@westos.com
Subject: ttttttttttt
dsadsa
.
EOT
[root@maillinux ~]# mailq
Mail queue is empty
在 maillinux.linux.com 的 student 用户上:
[student@maillinux ~]$ mail qun@linux.com
Subject: dddddd
dsa
sa
.
EOT
[student@maillinux ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? foR help.
"/var/spool/mail/student": 2 messages 2 new
>N 1 root Tue Mar 14 06:35 24/853 "taaaaaaaaaa"
N 2 Student User Tue Mar 14 06:42 22/668 "dddddd"
& q
这个群发只能发给有这个配置的主机上
4>邮件地址伪装:
入站地址伪装:
vim /etc/postfix/virtual
---------------
admin@qq.com root@linux.com ##全部伪装
@qq.com @linux.com ##仅对域名伪装
---------------
postmap /etc/postfix/virtual ##对文件加密
cd /etc/postfix/
ls
postconf -d | grep virtual
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
systemctl restart postfix.service
出站地址伪装:
别人读取到你的地址为你伪装的地址
vim /etc/postfix/generic
----------------
root@linux.com root@qq.com
----------------
把自己的地址伪装成 root@qq.com
postmap generic
postconf -d | grep generic
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
systemctl restart postfix.service
mail root@westos.com ##发给westos之后 邮件显示发送人为 root@qq.com
5>远程邮件发送(检测邮件发送服务配置是否成功):
在一台用户机上(不是上面两台主机)连接212给112发送邮件:
yum install telnet -y
systemctl restart telnet
telnet 172.25.254.212 25 ##连接212 的 25 端口 (25端口为邮件发送端口)
[root@mailwestos named]# telnet 172.25.254.212 25
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
220 miallinux.linux.com ESMTP Postfix
mail from:root@qq.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
djsakf
anlkf
csa
cdnlksa
.
250 2.0.0 Ok: queued as 60029247563
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
==========
邮件接受:
==========
1>接收服务的安装与端口开启
yum install dovecot ##提供邮件接收端口(110 143 993 995)pop3、imap协议
vim /etc/dovecot/dovecot.conf
--------------
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
--------------
vim /etc/dovecot/conf.d/10-mail.conf
------------
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
--------------
systemctl restart dovecot
开启邮件接收端口(110 143 993 995)
pop3 110
pop3s 995
imap 143
imaps 993
2>远程邮件接收(检测端口有没有开启):
yum install mutt -y
mutt -f pop://student@172.25.254.212 ##只能查看普通用户的 必须开启邮件接受端口
##172.25.254.212 下的 student
[student@maillinux ~]$ mkdir mail/.imap -p
[student@maillinux ~]$ touch mail/.imap/INBOX
为使所有的新用户都默认建立这个文件 在root下 /etc/skel/
mkdir mail/.imap -p
mail/.imap/INBOX
3>虚拟邮箱账户(mysql+dovecot+postfix)
mysql数据库配置:
yum install mariadb-server.x86_64 httpd php php-mysql -y ##安装数据库 php等基本配置
systemctl start mariadb
vim /etc/my.cnf ##添加以下内容
-----------
skip-networking=1 ##关闭数据库端口
----------
mysql_secure_installation ##设定数据库密码
cd /var/www/html/
scp kiosk@172.25.254.12:/home/kiosk/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 . ##拷贝一个数据库插件,以在浏览器上对数据库进行操作
ls
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages mysqladmin
rm -fr *.bz2
ls
cd mysqladmin/
ls
cp config.sample.inc.php config.inc.php
vim config.inc.php ##里面引号里的内容可以随便填写
systemctl restart mariadb
systemctl restart httpd
mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##创建用户
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##给用户授权
数据库信息:
数据库:email 表:mailuser
##编辑以下文件 使数据库与postfix连接
[root@maillinux postfix]# cat /etc/postfix/mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = username
where_field = username
[root@maillinux postfix]# cat /etc/postfix/mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = domain
where_field = domain
[root@maillinux postfix]# cat /etc/postfix/mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = maildir
where_field = username
##检测数据库与postfix连接成功与否
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.com/admin
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-user.cf
admin
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
##所有用户都使用vmail的身份,将他们家目录分开
groupadd -g 888 vmail
useradd -u 888 -g 888 vmail
cd /home/vmail/
postconf -d | grep virtual
postconf -e "virtual_mailbox_base = /home/vmail"
ll /home/vmail
postconf -e "virtual_gid_maps = static:888"
postconf -e "virtual_uid_maps = static:888"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
ll /etc/postfix/mysql-user.cf
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
ll /etc/postfix/mysql-mailbox.cf
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
ll /etc/postfix/mysql-domain.cf
[root@maillinux vmail]# tail -8 /etc/postfix/main.cf
#
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf
virtual_mailbox_base = /home/vmail
virtual_gid_maps = static:888
virtual_uid_maps = static:888
virtual_mailbox_maps = /etc/postfix/mysql-mailbox.cf
virtual_mailbox_domains = /etc/postfix/mysql-domain.cf
systemctl restart postfix.service
mail admin@redhat.com ##检测数据库里的虚拟用户能否使用
mailq
postqueue -f
mailq
cd /home/vmail/redhat.com/admin/new
cat 1489224408.Vfd01I27121cM454797.maillinux.linux.com
远程收件:(dovecot+mysql)
yum install dovecot-mysql -y
vim /etc/dovecot/dovecot.conf
---------------------------
48 login_trusted_networks = 0.0.0.0/0 ##允许访问地址网络
49 disable_plaintext_auth = no ##开启铭文认证
--------------------------
vim /etc/dovecot/conf.d/10-auth.conf
------------------
123 !include auth-sql.conf.ext ##开启数据库认证
------------------
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
vim dovecot-sql.conf.ext ##此文件里的诸多配置以自己建立的数据库信息为准
--------------------
32 driver = mysql
71 connect = host=localhost dbname=emial user=postfix password=postfix ##填写的是自己使用的数据库的信息
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM emailluser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE usrname = '%u'
----------------------
vim conf.d/10-mail.conf
----------
30 mail_location = maildir:/home/vmail/%d/%n ##用户家目录配置
----------
[root@maillinux dovecot]# systemctl restart dovecot
[root@maillinux dovecot]# telnet 172.25.254.212 110 ##检测mysql+dovecot配置有没有错
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user admin@redhat.com
+OK
pass 123
+OK Logged in.
quit
雷鸟服务端安装:
在其他机器上安装雷鸟(远程控制邮件接发的图形软件)
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
thunderbird
接下来的实验会有两个邮件服务主机:
mailwestos.westos.com 172.25.254.112
maillinux.linux.com 172.25.254.212
两个主机之间的交互通过 DNS 服务配置的邮件域名解析
DNS服务器被装在了 172.25.254.112 (mailwestos.westos.com) 上
Postfix服务: 提供SMTP协议,监听25端口
Dovecot服务:提供pop3协议,监听110端口
用户1给用户2发邮件:
用户1通过25端口(SMTP协议)将邮件发给主机
用户2登陆邮箱,通过110端口(pop3协议)从主机中读取邮件
用户可以通过25端口进行远程邮件发送
但是远程邮件的接收要通过110端口
110端口由pop3协议监听
dovecot服务提供pop3协议
所以,一个完整的邮件主机(用户能接收并发送邮件)必须具备两个服务:SMTP以及DOVECOT
不同主机之间的邮件交换必须通过DNS邮件域名解析
一个邮件主机上的用户可以是实体用户(服务器上真实存在的用户,下文中的root和student)
也可以是虚拟用户(每个用户的信息存在数据库中,这也是现在企业所提供的邮件服务方式)
下面就是具体配置:
===================
关于 DNS 的配置:
===================
服务端:ip:(mailwestos.westos.com)
yum install bind -y
vim /etc/named.conf
-----------
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
.
.
.
dnssec-validation no;
.
.
------------
vim /etc/named.rfc1912.zones
----------
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
};
---------
cd /var/named
ls
cp -p named.localhost westos.com.zone
vim westos.com.zone
cp -p westos.com.zone linux.com.zone
vim linux.com.zone
systemctl restart named
systemctl stop firewalld.service
-------------------------------------------------
[root@mailwestos named]# cat westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.112
westos.com. MX 1 172.25.254.112.
********************************************************
[root@mailwestos named]# cat linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.112
linux.com. MX 1 172.25.254.212.
----------------------------------------------------
测试端:ip:(maillinux.linux.com)
vim /etc/resolv.conf
---------------
nameserver 172.25.254.112
--------------
dig -t mx linux.com
dig -t mx westos.com
**********************************************
邮件收发之间没有关系
dovecot 收件服务 提供pop等协议 用户验证
**********************************************
==========
邮件发送:
==========
1>更改配置文件 开启25服务器接收端口
vim /etc/postfix/main.cf
-------------------------------
76 myhostname = mailwestos.westos.com
83 mydomain = westos.com
99 myorigin = $mydomain ##重写本地发布的电子邮件,使其显示为来自该域,确保响应返回入站邮件服务器
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
--------------------------------
systemctl restart postfix.service
mailq ##查看退回的邮件
postqueue -f ##刷新邮箱队列
mail ##查看邮箱/mysq
mail root@linux.com ##给 root@linux.com 发送邮件
2>邮件用户别名:
vim /etc/aliases
---------
admin: root
---------
root的别名
postalias /etc/aliases
在本机上进行更改后
别的主机上 发送邮件时用这个别名主机也能接受到
3>邮件群发:
在 maillinux.linux.com 上:
vim /etc/aliases
---------
qun: :include:/etc/postfix/users
---------
postalias /etc/aliases
vim /etc/postfix/users
----------
root
student
----------
测试:
在 mailwestos.westos.com 上:
[root@maillinux ~]# mail qun@westos.com
Subject: ttttttttttt
dsadsa
.
EOT
[root@maillinux ~]# mailq
Mail queue is empty
在 maillinux.linux.com 的 student 用户上:
[student@maillinux ~]$ mail qun@linux.com
Subject: dddddd
dsa
sa
.
EOT
[student@maillinux ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? foR help.
"/var/spool/mail/student": 2 messages 2 new
>N 1 root Tue Mar 14 06:35 24/853 "taaaaaaaaaa"
N 2 Student User Tue Mar 14 06:42 22/668 "dddddd"
& q
这个群发只能发给有这个配置的主机上
4>邮件地址伪装:
入站地址伪装:
vim /etc/postfix/virtual
---------------
admin@qq.com root@linux.com ##全部伪装
@qq.com @linux.com ##仅对域名伪装
---------------
postmap /etc/postfix/virtual ##对文件加密
cd /etc/postfix/
ls
postconf -d | grep virtual
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
systemctl restart postfix.service
出站地址伪装:
别人读取到你的地址为你伪装的地址
vim /etc/postfix/generic
----------------
root@linux.com root@qq.com
----------------
把自己的地址伪装成 root@qq.com
postmap generic
postconf -d | grep generic
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
systemctl restart postfix.service
mail root@westos.com ##发给westos之后 邮件显示发送人为 root@qq.com
5>远程邮件发送(检测邮件发送服务配置是否成功):
在一台用户机上(不是上面两台主机)连接212给112发送邮件:
yum install telnet -y
systemctl restart telnet
telnet 172.25.254.212 25 ##连接212 的 25 端口 (25端口为邮件发送端口)
[root@mailwestos named]# telnet 172.25.254.212 25
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
220 miallinux.linux.com ESMTP Postfix
mail from:root@qq.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
djsakf
anlkf
csa
cdnlksa
.
250 2.0.0 Ok: queued as 60029247563
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
==========
邮件接受:
==========
1>接收服务的安装与端口开启
yum install dovecot ##提供邮件接收端口(110 143 993 995)pop3、imap协议
vim /etc/dovecot/dovecot.conf
--------------
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
--------------
vim /etc/dovecot/conf.d/10-mail.conf
------------
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
--------------
systemctl restart dovecot
开启邮件接收端口(110 143 993 995)
pop3 110
pop3s 995
imap 143
imaps 993
2>远程邮件接收(检测端口有没有开启):
yum install mutt -y
mutt -f pop://student@172.25.254.212 ##只能查看普通用户的 必须开启邮件接受端口
##172.25.254.212 下的 student
[student@maillinux ~]$ mkdir mail/.imap -p
[student@maillinux ~]$ touch mail/.imap/INBOX
为使所有的新用户都默认建立这个文件 在root下 /etc/skel/
mkdir mail/.imap -p
mail/.imap/INBOX
3>虚拟邮箱账户(mysql+dovecot+postfix)
mysql数据库配置:
yum install mariadb-server.x86_64 httpd php php-mysql -y ##安装数据库 php等基本配置
systemctl start mariadb
vim /etc/my.cnf ##添加以下内容
-----------
skip-networking=1 ##关闭数据库端口
----------
mysql_secure_installation ##设定数据库密码
cd /var/www/html/
scp kiosk@172.25.254.12:/home/kiosk/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 . ##拷贝一个数据库插件,以在浏览器上对数据库进行操作
ls
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages mysqladmin
rm -fr *.bz2
ls
cd mysqladmin/
ls
cp config.sample.inc.php config.inc.php
vim config.inc.php ##里面引号里的内容可以随便填写
systemctl restart mariadb
systemctl restart httpd
mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##创建用户
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##给用户授权
数据库信息:
数据库:email 表:mailuser
##编辑以下文件 使数据库与postfix连接
[root@maillinux postfix]# cat /etc/postfix/mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = username
where_field = username
[root@maillinux postfix]# cat /etc/postfix/mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = domain
where_field = domain
[root@maillinux postfix]# cat /etc/postfix/mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = emial
table = mailuser
select_field = maildir
where_field = username
##检测数据库与postfix连接成功与否
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.com/admin
[root@maillinux postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-user.cf
admin
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
##所有用户都使用vmail的身份,将他们家目录分开
groupadd -g 888 vmail
useradd -u 888 -g 888 vmail
cd /home/vmail/
postconf -d | grep virtual
postconf -e "virtual_mailbox_base = /home/vmail"
ll /home/vmail
postconf -e "virtual_gid_maps = static:888"
postconf -e "virtual_uid_maps = static:888"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
ll /etc/postfix/mysql-user.cf
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
ll /etc/postfix/mysql-mailbox.cf
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
ll /etc/postfix/mysql-domain.cf
[root@maillinux vmail]# tail -8 /etc/postfix/main.cf
#
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf
virtual_mailbox_base = /home/vmail
virtual_gid_maps = static:888
virtual_uid_maps = static:888
virtual_mailbox_maps = /etc/postfix/mysql-mailbox.cf
virtual_mailbox_domains = /etc/postfix/mysql-domain.cf
systemctl restart postfix.service
mail admin@redhat.com ##检测数据库里的虚拟用户能否使用
mailq
postqueue -f
mailq
cd /home/vmail/redhat.com/admin/new
cat 1489224408.Vfd01I27121cM454797.maillinux.linux.com
远程收件:(dovecot+mysql)
yum install dovecot-mysql -y
vim /etc/dovecot/dovecot.conf
---------------------------
48 login_trusted_networks = 0.0.0.0/0 ##允许访问地址网络
49 disable_plaintext_auth = no ##开启铭文认证
--------------------------
vim /etc/dovecot/conf.d/10-auth.conf
------------------
123 !include auth-sql.conf.ext ##开启数据库认证
------------------
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
vim dovecot-sql.conf.ext ##此文件里的诸多配置以自己建立的数据库信息为准
--------------------
32 driver = mysql
71 connect = host=localhost dbname=emial user=postfix password=postfix ##填写的是自己使用的数据库的信息
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM emailluser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE usrname = '%u'
----------------------
vim conf.d/10-mail.conf
----------
30 mail_location = maildir:/home/vmail/%d/%n ##用户家目录配置
----------
[root@maillinux dovecot]# systemctl restart dovecot
[root@maillinux dovecot]# telnet 172.25.254.212 110 ##检测mysql+dovecot配置有没有错
Trying 172.25.254.212...
Connected to 172.25.254.212.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user admin@redhat.com
+OK
pass 123
+OK Logged in.
quit
雷鸟服务端安装:
在其他机器上安装雷鸟(远程控制邮件接发的图形软件)
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
thunderbird