######################

### dovecot+ mysql ###

######################

1.yum install dovecot dovecot-mysql -y   

   ##dovecot是一个开源的 IMAP 和 POP3 邮件服务器,支持 Linux,支持发送邮件

   ##dovecot-mysql是dovecot的插件,让dovecot识别MySQL

  systemctl start httpd


dovecot+mysql 收件服务、空壳邮件_邮件



  2. vim /etc/dovecot/dovecot.conf

dovecot+mysql 收件服务、空壳邮件_邮件_02

dovecot+mysql 收件服务、空壳邮件_服务器_03

 24 protocols = imap pop3 lmtp  ##支持的收件协议

dovecot+mysql 收件服务、空壳邮件_服务器_04

 48 login_trusted_networks = 0.0.0.0/0  ##信任任何网络

 49 disable_plaintext_auth = no   ##开启明文认证

 

 3. vim /etc/dovecot/conf.d/10-auth.conf

dovecot+mysql 收件服务、空壳邮件_Linux_05

  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配置

dovecot+mysql 收件服务、空壳邮件_服务器_06



  5.vim /etc/dovecot/dovecot-sql.conf.ext 

dovecot+mysql 收件服务、空壳邮件_服务器_07

dovecot+mysql 收件服务、空壳邮件_Linux_08 

  32 driver = mysql    ##数据库类型


dovecot+mysql 收件服务、空壳邮件_服务器_09

  71 connect = host=localhost dbname=email user=postuser password=123  ##查询用到的数据    库,用户和密码



dovecot+mysql 收件服务、空壳邮件_Linux_10

  78 default_pass_scheme = PLAIN   ##默认认证方式为明文


dovecot+mysql 收件服务、空壳邮件_邮件_11

  107 password_query = \     ##查询密码匹配

  108 SELECT username, domain, password \     ##查询用户,域名,密码

  109 FROM emailuser WHERE username = '%u' AND domain = '%d'   ##从emailuser表中查询



dovecot+mysql 收件服务、空壳邮件_邮件_12

  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 

 dovecot+mysql 收件服务、空壳邮件_服务器_13

dovecot+mysql 收件服务、空壳邮件_服务器_14

  30 mail_location = maildir:/home/vmail/%d/%n  ##指定邮件位置


dovecot+mysql 收件服务、空壳邮件_Linux_15

  168 first_valid_uid = 666     ##邮件查询用户身份

  175 first_valid_gid = 666



  7.systemctl restart dovecot.service  ##重启dovecot服务

  

  **测试

[root@foundation15 Desktop]# telnet 172.25.254.115 110

Trying 172.25.254.115...

Connected to 172.25.254.115.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user lee@lee.com

+OK

pass lee

+OK Logged in.

quit

+OK Logging out.

Connection closed by foreign host.

  


#########################

#### postfix 空壳邮件 ###

#########################

 

desktop.server的myorigin一样

~server

vim /etc/postfix/main.cf

75 myhostname = server   ## 设置为真实的主机域名

dovecot+mysql 收件服务、空壳邮件_服务器_16

83 mydomain = example.com

dovecot+mysql 收件服务、空壳邮件_邮件_17

99 myorigin = $mydomain

dovecot+mysql 收件服务、空壳邮件_Linux_18

113 inet_interfaces = all

dovecot+mysql 收件服务、空壳邮件_Linux_19

164 mydestination =    ##空壳邮件不接受邮件,所以不设置

dovecot+mysql 收件服务、空壳邮件_邮件_20

316 relayhost = 172.25.254.115   ##接替的真实主机的IP

 dovecot+mysql 收件服务、空壳邮件_邮件_21

systemctl restart postfix.service

 

~desktop

myhostname = desktop

mydomain = westos.com

myorigin = example.com

 

~server

mail root@westos.com

server是desktop的空壳,

**测试

空壳主机给本机root发送邮件,174主机接收到邮件