1.yum install dovecot dovecot-mysql.x86_64 -y
##dovecot是一个开源的 IMAP 和 POP3 邮件服务器,支持 Linux,支持发送邮件
##dovecot-mysql是dovecot的插件,让dovecot识别MySQL
2. vim /etc/dovecot/dovecot.conf
24 protocols = imap pop3 lmtp ##支持的收件协议
48 login_trusted_networks = 0.0.0.0/0 ##信任任何网络
49 disable_plaintext_auth = no ##开启明文认证
3. vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##开启MySQL认证方式
4. cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
##生成dovecot读取MySQL配置
5.vim /etc/dovecot/dovecot-sql.conf.ext
32 driver = mysql ##数据库类型
71 connect = host=localhost dbname=email user=postuser password=123 ##查询用到的数据 库,用户和密码
78 default_pass_scheme = PLAIN ##默认认证方式为明文
107 password_query = \ ##查询密码匹配
108 SELECT username, domain, password \ ##查询用户,域名,密码
109 FROM emailuser WHERE username = '%u' AND domain = '%d' ##从emailuser表中查询
125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHERE username ='%u' ##查询邮件内部内容
6. vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n ##指定邮件位置
168 first_valid_uid = 666 ##邮件查询用户身份
175 first_valid_gid = 666
7.systemctl restart dovecot.service ##重启dovecot服务
**测试
8.空壳邮件
vim /etc/postfix/main.cf
myorigin = westos.com ## 设置为真实的主机域名
mydestination = ##空壳邮件不接受邮件,所以不设置
relayhost = 172.25.254.174 ##接替的真实主机的IP
**测试
空壳主机给本机root发送邮件,174主机接收到邮件
本文转自 red777 51CTO博客,原文链接:http://blog.51cto.com/12314711/1930552

![[VU83YDZ]P9K7@ZLF_Q9M%1.png wKiom1krjkjwIEWjAAAnfPiaAD0770.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/40a5e9f81d4a470286708de6f39c218f.png?x-oss-process=image/resize,w_1400/format,webp)
![~L6%CB07]L~]UIR(4[I[RF0.png wKiom1krjt3BNC_vAABmEs6p-aY131.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/1dfc6599b54c4890862d83cfa2c2c910.png?x-oss-process=image/resize,w_1400/format,webp)







![)%GS`250(D)])LQPZP}T]5M.png wKiom1krkzOAryI-AACE8qjDa00097.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/a7b7a6892b404206a96d0ddfe8c7b4a7.png?x-oss-process=image/resize,w_1400/format,webp)

![{[G80F~[P%3FQ]5LF{N5]DQ.png wKioL1krlEGSTRz6AABmjTtvN7c137.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/d04b9732570d47f8985e89bd5e6e9fa6.png?x-oss-process=image/resize,w_1400/format,webp)
![@O]OD{(VMJE3Q0WFTSPSF)P.png wKioL1krlMiBSevwAAAaY-wNYOo918.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/8119a9e622454425b8c454c1d3d2a430.png?x-oss-process=image/resize,w_1400/format,webp)


![QU$M8P}LDA@RL$4%]677O(C.png wKioL1krlyvR0zjdAABLhFUtKJw043.png](https://ucc.alicdn.com/77hzxr65teps2/developer-article542493/20241019/775541061b4b41098bf160a7e35e80d4.png?x-oss-process=image/resize,w_1400/format,webp)
