首页 > 代码库 > 三.mail 接收权限 dovecot加密通信 php数据库 thunderbird
三.mail 接收权限 dovecot加密通信 php数据库 thunderbird
postconf -d:查看默认设置
postconf -n:查看当前设置
postconf -e "inet_interfaces = all":修改选项
inet_interfaces 参数指定postfix系统监听的网络接口。
一.邮件的限制
==access== ##禁止某个ip接受邮件
[root@maillinux ~]# cd /etc/postfix/
[root@maillinux postfix]# ls
access generic main.cf relocated virtual
canonical header_checks master.cf transport
[root@maillinux postfix]# vim access
172.25.254.15 REJECT
[root@maillinux postfix]# postmap access
[root@maillinux postfix]# ls
access canonical header_checks master.cf transport
access.db generic main.cf relocated virtual
[root@maillinux postfix]# postconf -d |grep smtpd_client_restrictions
smtpd_client_restrictions =
[root@maillinux postfix]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
[root@maillinux postfix]# postconf -d |grep smtpd_client_restrictions
smtpd_client_restrictions =
##太长了?
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
[root@maillinux postfix]# systemctl restart postfix.service
--测试--
[kiosk@foundation15 Desktop]$ telnet 172.25.254.115 25
Trying 172.25.254.115...
Connected to 172.25.254.115.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:root@linux.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <unknown[172.25.254.15]>: Client host rejected: Access denied
quit
Connection closed by foreign host.
==sender== ##禁止某个用户发送邮件
[root@maillinux postfix]# vim access
删除
172.25.254.15 REJECT
[root@maillinux postfix]# postmap access
[root@maillinux postfix]# ls
access canonical header_checks master.cf transport
access.db generic main.cf relocated virtual
[root@maillinux postfix]# vim sender
student@linux.com REJECT
[root@maillinux postfix]# postmap sender
[root@maillinux postfix]# postconf -d |grep smtpd_sender_restrictions
smtpd_sender_restrictions =
[root@maillinux postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
[root@maillinux postfix]# postconf -d |grep smtpd_sender_restrictionssmtpd_sender_restrictions =
##太长了?
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
[root@maillinux postfix]# systemctl restart postfix.service
--测试--
[kiosk@foundation15 Desktop]$ telnet 172.25.254.115 25
Trying 172.25.254.115...
Connected to 172.25.254.115.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:student@linux.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <student@linux.com>: Sender address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.
==recipient== ##禁止某个用户接受邮件
[root@maillinux postfix]# vim recip
student@linux.com REJECT
[root@maillinux postfix]# postmap recip
[root@maillinux postfix]# postconf -d |grep smtpd_recipient_restrictions
smtpd_recipient_restrictions =
[root@maillinux postfix]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip
[root@maillinux postfix]# systemctl restart postfix.service
--测试--
[kiosk@foundation15 Desktop]$ telnet 172.25.254.115 25
Trying 172.25.254.115...
Connected to 172.25.254.115.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:root@linux.com
250 2.1.0 Ok
rcpt to:student@linux.com
554 5.7.1 <student@linux.com>: Recipient address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.
二.dovecot 加密通信
----------------------
dovecot
提供服务
imap 143 pop3 110 imaps 993 pop3s 995
49不支持明文的话,不能用imap和pop3
按o
----------------------
==客户端==
[root@maillinux postfix]# vim main.cf
删除
680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
681 smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
682 smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/reci p
[root@maillinux postfix]# systemctl restart postfix.service
[root@mailwestos ~]# cat /etc/services |grep imap
imap 143/tcp imap2 # Interim Mail Access Proto v2
imap 143/udp imap2
imap3 220/tcp # Interactive Mail Access
imap3 220/udp # Protocol v3
imaps 993/tcp # IMAP over SSL
imaps 993/udp # IMAP over SSL
berknet 2005/tcp csync # csync for cyrus-imapd
oracle 2005/udp csync # csync for cyrus-imapd
[root@mailwestos ~]# cat /etc/services |grep pop
# unfortunately the poppassd (Eudora) uses a port which has already
# been assigned to a different service. We list the poppassd as an
#3com-tsmux 106/tcp poppassd
#3com-tsmux 106/udp poppassd
pop2 109/tcp pop-2 postoffice # POP version 2
pop2 109/udp pop-2
pop3 110/tcp pop-3 # POP version 3
pop3 110/udp pop-3
pop3s 995/tcp # POP-3 over SSL
pop3s 995/udp # POP-3 over SSL
kpop 1109/tcp # Pop with Kerberos
poppassd 106/tcp # Eudora
poppassd 106/udp # Eudora
hybrid-pop 473/tcp # hybrid-pop
hybrid-pop 473/udp # hybrid-pop
winpoplanmess 1152/tcp # Winpopup LAN Messenger
winpoplanmess 1152/udp # Winpopup LAN Messenger
popup-reminders 7787/tcp # Popup Reminders Receive
popup-reminders 7787/udp # Popup Reminders Receive
[root@mailwestos ~]# yum install dovecot -y ##dovecot(加密通信)
......
[root@mailwestos ~]# cd /etc/dovecot
[root@mailwestos dovecot]# vim dovecot.conf
-----------------------------------------------
24 protocols = imap pop3 lmtp
46 # for authentication checks). disable_plaintext_auth is also ignored for
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
-----------------------------------------------
[root@mailwestos dovecot]# cd conf.d
[root@mailwestos conf.d]# ls
10-auth.conf 20-imap.conf auth-dict.conf.ext
10-director.conf 20-lmtp.conf auth-ldap.conf.ext
10-logging.conf 20-pop3.conf auth-master.conf.ext
10-mail.conf 90-acl.conf auth-passwdfile.conf.ext
10-master.conf 90-plugin.conf auth-sql.conf.ext
10-ssl.conf 90-quota.conf auth-static.conf.ext
15-lda.conf auth-checkpassword.conf.ext auth-system.conf.ext
15-mailboxes.conf auth-deny.conf.ext auth-vpopmail.conf.ext
[root@mailwestos conf.d]# vim 10-mail.conf
-----------------------------------------------
17 # %u - username
25 # mail_location = mbox:~/mail:INBOX=/var/mail/%u
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
-----------------------------------------------
[root@mailwestos conf.d]# ll /var/mail
lrwxrwxrwx. 1 root root 10 May 6 2014 /var/mail -> spool/mail
[root@mailwestos conf.d]# ll /var/spool/mail/
total 4
-rw-------. 1 root mail 1263 Dec 2 20:50 root
-rw-rw----. 1 rpc mail 0 May 6 2014 rpc
-rw-rw----. 1 student mail 0 Jul 10 2014 student
[root@mailwestos mail]# ls /var/mail
root rpc student
[root@mailwestos mail]# systemctl start dovecot
[root@mailwestos mail]# netstat -antlpe | grep dovecot
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 0 87375 32078/dovecot
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 0 87351 32078/dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 0 87349 32078/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 0 87373 32078/dovecot
tcp6 0 0 :::993 :::* LISTEN 0 87376 32078/dovecot
tcp6 0 0 :::995 :::* LISTEN 0 87352 32078/dovecot
tcp6 0 0 :::110 :::* LISTEN 0 87350 32078/dovecot
tcp6 0 0 :::143 :::* LISTEN 0 87374 32078/dovecot
[root@mailwestos mail]# useradd westos
[root@mailwestos mail]# passwd westos
Changing password for user westos.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
mutt -s "subject" -a /backup/backup.tar.gz xxx@126.com < /tmp/x.txt
-s:邮件标题,用""括上。
-a:邮件附件。如上命令就是将/backup目录下 backup.tar.gz文件作为附件发送。
< /tmp/x.txt: /tmp目录下x.txt文件里的内容作为邮件内容发送。
[root@foundation15 ~]# yum install mutt -y ##mutt邮件发送
[root@foundation15 ~]# mutt -f pop://westos@172.25.254.215
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.254.215:
##弹出
[root@mailwestos mail]# cat /var/log/message
发现:Error: chown(/home/westos/mail/.imap, group=12(mail)) failed
[root@mailwestos mail]# su - westos
[westos@mailwestos ~]$ ls
mail
[westos@mailwestos ~]$ cd mail
[westos@mailwestos mail]$ ls
[westos@mailwestos mail]$ mkdir .imap
[westos@mailwestos mail]$ exit
logout
[root@mailwestos mail]# > /var/log/maillog
[root@mailwestos mail]# tail -f /var/log/maillog
三.mutt邮箱
[root@foundation15 ~]# mutt -f pop://westos@172.25.254.215
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.254.215:
##弹出
[root@mailwestos mail]# tail -f /var/log/maillog
发现
Error: chown(/home/westos/mail/.imap/INBOX, group=12(mail)) failed
[root@mailwestos mail]# ps aux |grep dovecot
root 32078 0.0 0.1 19840 1556 ? Ss Dec02 0:00 /usr/sbin/dovecot -F
dovecot 32081 0.0 0.0 9312 980 ? S Dec02 0:00 dovecot/anvil
root 32082 0.0 0.1 9440 1152 ? S Dec02 0:00 dovecot/log
root 32320 0.0 0.0 112640 940 pts/0 S+ 00:04 0:00 grep --color=auto dovecot
[root@mailwestos mail]# su - westos
Last login: Sat Dec 3 00:01:23 EST 2016 on pts/0
[westos@mailwestos ~]$ touch /home/westos/mail/.imap/INBOX
[root@foundation15 ~]# mutt -f pop://westos@172.25.254.215
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.254.215:
##进入
q
##退出
[root@mailwestos mail]# su - student
[student@mailwestos ~]$ ls -a
. .. .bash_logout .bash_profile .bashrc .cache .config .ssh
[student@mailwestos ~]$ logout
[root@mailwestos mail]# cd /etc/skel/
[root@mailwestos skel]# ls -a
. .. .bash_logout .bash_profile .bashrc .config .mozilla
[root@mailwestos skel]# mkdir mail/.imap/ -p
[root@mailwestos skel]# touch mail/.imap/INBOX
[root@mailwestos skel]# cd
[root@mailwestos ~]# useradd lee
[root@mailwestos ~]# su - lee
[lee@mailwestos ~]$ ls
mail
[lee@mailwestos ~]$ cd mail/
[lee@mailwestos mail]$ ls -a
. .. .imap
[lee@mailwestos mail]$ cd .imap/
[lee@mailwestos .imap]$ ls
INBOX
[lee@mailwestos .imap]$ ll
total 0
-rw-r--r--. 1 lee lee 0 Dec 3 00:15 INBOX
[lee@mailwestos .imap]$ logout
[root@mailwestos ~]# passwd lee
Changing password for user lee.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@foundation15 ~]# mutt -f pop://lee@172.25.254.215
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for lee@172.25.254.215:
##进入
q
##退出
[root@maillinux postfix]# yum install lftp -y
......
[root@maillinux postfix]# cd /mnt
[root@maillinux postfix]# lftp 172.25.254.250
lftp 172.25.254.250:~> cd /pub/docs/software
cd ok, cwd=/pub/docs/software
lftp 172.25.254.250:/pub/docs/software> ls
-rwxr-xr-x 1 1000 1000 3086326 Dec 25 2013 phpMyAdmin-2.11.3-all-languages.tar.bz2
-rwxr-xr-x 1 1000 1000 4548030 Dec 25 2013 phpMyAdmin-3.4.0-all-languages.tar.bz2
-rw-rw-r-- 1 1000 1000 2713600 Jun 07 2015 taobao.tar
-rwxr-xr-x 1 1000 1000 52387876 Feb 01 2015 thunderbird-31.2.0-1.el7.x86_64.rpm
-rwxr-xr-x 1 1000 1000 36902724 Feb 01 2015 thunderbird-31.4.0.tar.bz2
lftp 172.25.254.250:/pub/docs/software> get thunderbird-31.4.0.tar.bz2
36902724 bytes transferred
lftp 172.25.254.250:/pub/docs/software> quit
[root@maillinux mnt]# ls
thunderbird-31.4.0.tar.bz2
[root@maillinux mnt]# tar jxf thunderbird-31.4.0.tar.bz2
[root@maillinux mnt]# ls
thunderbird thunderbird-31.4.0.tar.bz2
[root@maillinux mnt]# cd thunderbird/
[root@maillinux thunderbird]# ls
application.ini libldif60.so libxul.so
blocklist.xml libmozalloc.so mozilla-xremote-client
chrome libmozsqlite3.so omni.ja
chrome.manifest libnspr4.so platform.ini
components libnss3.so plugin-container
crashreporter libnssckbi.so precomplete
crashreporter.ini libnssdbm3.chk removed-files
defaults libnssdbm3.so run-mozilla.sh
dependentlibs.list libnssutil3.so searchplugins
dictionaries libplc4.so Throbber-small.gif
extensions libplds4.so thunderbird
icons libprldap60.so thunderbird-bin
isp libsmime3.so updater
libfreebl3.chk libsoftokn3.chk updater.ini
libfreebl3.so libsoftokn3.so update-settings.ini
libldap60.so libssl3.so
[root@maillinux thunderbird]# ./thunderbird
-bash: ./thunderbird: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
[root@maillinux thunderbird]# yum whatprovides /lib/ld-linux.so.2
Loaded plugins: langpacks
rhel_dvd/filelists_db | 3.0 MB 00:00
glibc-2.17-55.el7.i686 : The GNU libc libraries
Repo : rhel_dvd
Matched from:
Filename : /lib/ld-linux.so.2
[root@maillinux thunderbird]# yum install glibc-2.17-55.el7.i686 -y
......
---类似方法,直到装好---
144 ./thunderbird
145 yum whatprovides /lib/ld-linux.so.2
146 yum install glibc-2.17-55.el7.i686 -y
147 ./thunderbird
148 yum whatprovides */libstdc++.so.6
149 yum install libstdc++-4.8.2-16.el7.i686 -y
150 ./thunderbird
151 yum whatprovides */libXrender.so.1
152 yum install libXrender-0.9.8-2.1.el7.i686 -y
153 ./thunderbird
154 yum whatprovides */libasound.so.2
155 yum install alsa-lib-1.0.27.2-3.el7.i686 -y
156 ./thunderbird
157 yum whatprovides */libdbus-glib-1.so.2
158 yum install dbus-glib-0.100-7.el7.i686 -y
159 ./thunderbird
160 yum whatprovides */libgtk-x11-2.0.so.0
161 yum install gtk2-2.24.22-5.el7.i686 -y
162 ./thunderbird
163 yum whatprovides */libXt.so.6
164 yum install libXt-1.1.4-6.1.el7.i686 -y
165 ./thunderbird
[root@maillinux thunderbird]# ./thunderbird &
登陆
设定帐号westos(略),同下面lee设定
[root@mailwestos ~]# mail westos@westos.com
Subject: 111
111
111
.
EOT
[root@mailwestos ~]# mailq
Mail queue is empty
查看图形,收到邮件111
左边空白处右键点击设定,帐号操作,新增电子邮箱帐号
您的大名:lee
电子邮件地址:lee@westos.com
密码:lee
记住密码
-->继续
IMAP 172.25.254.215 143 无 自动检测
SMTP 172.25.254.215 25 无 自动检测
-->重新测试
-->完成
我了解危险性>打钩
-->完成
-->确定
写信
至:westos@westos.com
主旨:22
内文:
222
222
-->传送
查看westos@westos.com收件夹
收到邮件:222
[root@mailwestos ~]# mail -u westos
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/westos": 2 messages 1 unread
1 root Sat Dec 3 00:40 22/669 "111"
>U 2 lee Sat Dec 3 00:46 22/750 "222"
& 2
Message 2:
From lee@westos.com Sat Dec 3 00:46:50 2016
Return-Path: <lee@westos.com>
X-Original-To: westos@westos.com
Delivered-To: westos@westos.com
Date: Sat, 03 Dec 2016 00:46:50 -0500
From: lee <lee@westos.com>
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
To: westos@westos.com
Subject: 222
Content-Type: text/plain; charset=utf-8; format=flowed
X-UID: 2
Status: RO
222
222
& q
Held 2 messages in /var/mail/westos
[root@foundation15 ~]# telnet 172.25.254.215 110
Trying 172.25.254.215...
Connected to 172.25.254.215.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user student
+OK
pass student
-ERR [SYS/PERM] Permission denied
Connection closed by foreign host.
##权限不够
[root@foundation15 ~]# telnet 172.25.254.215 110
Trying 172.25.254.215...
Connected to 172.25.254.215.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user lee
+OK
pass lee
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
==smtp连接mysql==
107 yum install httpd php php-mysql -y
108 yum instal lftp
109 yum install lftp -y
110 yum install mariadb-server.x86_64 -y
[root@mailwestos ~]# cd /var/www/html/
[root@mailwestos ~]# lftp 172.25.254.250
lftp 172.25.254.250:~> cd /pub/docs/software
cd ok, cwd=/pub/docs/software
lftp 172.25.254.250:/pub/docs/software> ls
-rwxr-xr-x 1 1000 1000 3086326 Dec 25 2013 phpMyAdmin-2.11.3-all-languages.tar.bz2
-rwxr-xr-x 1 1000 1000 4548030 Dec 25 2013 phpMyAdmin-3.4.0-all-languages.tar.bz2
-rw-rw-r-- 1 1000 1000 2713600 Jun 07 2015 taobao.tar
-rwxr-xr-x 1 1000 1000 52387876 Feb 01 2015 thunderbird-31.2.0-1.el7.x86_64.rpm
-rwxr-xr-x 1 1000 1000 36902724 Feb 01 2015 thunderbird-31.4.0.tar.bz2
lftp 172.25.254.250:/pub/docs/software> get phpMyAdmin-3.4.0-all-languages.tar.bz2
4548030 bytes transferred
lftp 172.25.254.250:/pub/docs/software> quit
[root@mailwestos html]# ls
phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# ls
phpMyAdmin-3.4.0-all-languages phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin
[root@mailwestos html]# cd myadmin/
[root@mailwestos myadmin]# cp -p config.sample.inc.php config.inc.php
[root@mailwestos myadmin]# vim config.inc.php
17 $cfg[‘blowfish_secret‘] = ‘westos‘; /* YOU MUST FILL IN THIS FOR COOKIE AU TH! */
[root@mailwestos myadmin]# systemctl start httpd
[root@mailwestos myadmin]# systemctl start mariadb
[root@mailwestos myadmin]# mysql_secure_installation
密码:westos
[root@mailwestos myadmin]# systemctl restart mariadb
[root@mailwestos myadmin]# cd
[root@mailwestos ~]# firefox &
配置email库muser表4个字段
插入一行用户信息
表用户的域一定要和本机的域 区分开
root@mailwestos ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> select * from email.muser;
+------------------+----------+------------+-------------------------------+
| username | password | domain | maildir |
+------------------+----------+------------+-------------------------------+
| admin@westos.org | 123 | westos.org | /home/vmail/westos.org/admin/ |
+------------------+----------+------------+-------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> CREATE USER postfix@localhost identified by ‘postfix‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT INSERT,UPDATE,SELECT on email.* to postfix@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@mailwestos ~]# mysql -upostfix -ppostfix
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> SELECT * FROM email.muser;
+------------------+----------+------------+-------------------------------+
| username | password | domain | maildir |
+------------------+----------+------------+-------------------------------+
| admin@westos.org | 123 | westos.org | /home/vmail/westos.org/admin/ |
+------------------+----------+------------+-------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> quit
[root@mailwestos ~]# cd /etc/postfix/
[root@mailwestos postfix]# vim mysql-users.cf
1 hosts = localhost
2 user = postfix
3 password = postfix
4 dbname = email
5 table = muser
6 select_field = username
7 where_field = username
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-users.cf
admin@westos.org
[root@mailwestos postfix]# vim mysql-domain.cf
6 select_field = domain
7 where_field = domain
[root@mailwestos postfix]# postmap -q "westos.org" mysql:/etc/postfix/mysql-domain.cf
westos.org
[root@mailwestos postfix]# vim mysql-maildir.cf
6 select_field = maildir
7 where_field = username
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-maildir.cf
/home/vmail/westos.org/admin/
网页上添加一个lee用户
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-users.cf
admin@westos.org
[root@mailwestos postfix]# postmap -q "westos.org" mysql:/etc/postfix/mysql-domain.cf
westos.org,westos.org
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-maildir.cf
/home/vmail/westos.org/admin/
[root@mailwestos postfix]# groupadd vmail -g 666
[root@mailwestos postfix]# useradd -u 666 -g 666 -s /sbin/nologin vmail
[root@mailwestos postfix]# postconf -d | grep virtual
...... ##不要自己敲,尽量复制粘贴
[root@mailwestos postfix]# postconf -e "virtual_gid_maps = static:666"
[root@mailwestos postfix]# postconf -e "virtual_uid_maps = static:666"
[root@mailwestos postfix]# postconf -e "virtual_mailbox_base = /home/vmail"
[root@mailwestos postfix]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf"
[root@mailwestos postfix]# ll /etc/postfix/mysql-users.cf
-rw-r--r--. 1 root root 128 Dec 3 02:34 /etc/postfix/mysql-users.cf
[root@mailwestos postfix]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
[root@mailwestos postfix]# ll /etc/postfix/mysql-domain.cf
-rw-r--r--. 1 root root 124 Dec 3 02:37 /etc/postfix/mysql-domain.cf
[root@mailwestos postfix]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf"
[root@mailwestos postfix]# ll /etc/postfix/mysql-maildir.cf
-rw-r--r--. 1 root root 127 Dec 3 02:38 /etc/postfix/mysql-maildir.cf
vim /etc/postfix/main.cf
virtual_gid_maps = static:666
virtual_uid_maps = static:666
virtual_mailbox_base = /home/vmail
virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf
修改数据库maildir字段
[root@mailwestos postfix]# mysql -upostfix -ppostfix
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> SELECT * FROM email.muser;
+------------------+----------+------------+-------------------+
| username | password | domain | maildir |
+------------------+----------+------------+-------------------+
| admin@westos.org | 123 | westos.org | westos.org/admin/ |
| lee@westos.org | 123 | westos.org | westos.org/lee/ |
+------------------+----------+------------+-------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@mailwestos ~]# mail admin@westos.org
Subject: test
test
.
EOT
[root@mailwestos ~]# mailq
Mail queue is empty
[root@mailwestos ~]# cd /home
[root@mailwestos home]# ls
lee student vmail westos
[root@mailwestos home]# cd vmail
[root@mailwestos vmail]# ls
mail westos.org ##哪来的mail,应该只有westos.org
[root@mailwestos vmail]# cd westos.org/
[root@mailwestos westos.org]# ls
admin
[root@mailwestos westos.org]# cd admin
[root@mailwestos admin]# ls
cur new tmp
[root@mailwestos vmail]# cd /etc/dovecot/
[root@mailwestos dovecot]# ls
conf.d dovecot.conf
[root@mailwestos dovecot]# cd conf.d/
[root@mailwestos conf.d]# ls
10-auth.conf 20-imap.conf auth-dict.conf.ext
10-director.conf 20-lmtp.conf auth-ldap.conf.ext
10-logging.conf 20-pop3.conf auth-master.conf.ext
10-mail.conf 90-acl.conf auth-passwdfile.conf.ext
10-master.conf 90-plugin.conf auth-sql.conf.ext
10-ssl.conf 90-quota.conf auth-static.conf.ext
15-lda.conf auth-checkpassword.conf.ext auth-system.conf.ext
15-mailboxes.conf auth-deny.conf.ext auth-vpopmail.conf.ext
[root@mailwestos conf.d]# vim 10-auth.conf
122 !include auth-system.conf.ext
123 !include auth-sql.conf.ext
[root@mailwestos conf.d]# vim auth-sql.conf.ext
8 # Path for SQL configuration file, see example-config/dovecot-sql.conf.e xt
[root@mailwestos conf.d]# cd /usr/share/doc/dovecot-2.2.10/
[root@mailwestos dovecot-2.2.10]# ls
AUTHORS COPYING.LGPL dovecot-openssl.cnf NEWS wiki
ChangeLog COPYING.MIT example-config README
COPYING documentation.txt mkcert.sh solr-schema.xml
[root@mailwestos dovecot-2.2.10]# cd example-config/
[root@mailwestos example-config]# ls
conf.d dovecot-dict-auth.conf.ext dovecot-ldap.conf.ext
dovecot.conf dovecot-dict-sql.conf.ext dovecot-sql.conf.ext
[root@mailwestos example-config]# cp dovecot-sql.conf.ext /etc/dovecot/
[root@mailwestos example-config]# cd /etc/dovecot/
[root@mailwestos dovecot]# ls
conf.d dovecot.conf dovecot-sql.conf.ext
[root@mailwestos dovecot]# vim dovecot-sql.conf.ext
32 driver = mysql
71 connect = host=localhost dbname=email user=postfix password=postfix
78 default_pass_scheme = PLAIN
107 password_query = \
108 SELECT username, domain, password \
109 FROM muser WHERE username = ‘%u‘ AND domain = ‘%d‘
125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM muser WHERE username = ‘%u‘
[root@mailwestos dovecot]# cd conf.d/
[root@mailwestos conf.d]# vim 10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n
168 first_valid_uid = 666
175 first_valid_gid = 666
[root@mailwestos conf.d]# systemctl restart dovecot.service
[root@mailwestos conf.d]# yum install telnet -y
[root@mailwestos conf.d]# telnet 172.25.254.215 110
Trying 172.25.254.215...
Connected to 172.25.254.215.
Escape character is ‘^]‘.
-ERR Disconnected: Auth process broken
Connection closed by foreign host.
[root@mailwestos conf.d]# tail -n 5 /var/log/maillog
发现
Dec 3 03:53:30 maillinux dovecot: auth: Fatal: Unknown database driver ‘mysql‘
[root@mailwestos conf.d]# yum search dovecot
Loaded plugins: langpacks
============================ N/S matched: dovecot ============================
dovecot-mysql.x86_64 : MySQL back end for dovecot
dovecot-pgsql.x86_64 : Postgres SQL back end for dovecot
dovecot-pigeonhole.x86_64 : Sieve and managesieve plug-in for dovecot
dovecot.i686 : Secure imap and pop3 server
dovecot.x86_64 : Secure imap and pop3 server
Name and summary matches only, use "search all" for everything.
[root@mailwestos conf.d]# yum install dovecot-mysql -y
......
[root@mailwestos conf.d]# systemctl restart dovecot.service
[root@mailwestos conf.d]# telnet 172.25.254.215 110
Trying 172.25.254.215...
Connected to 172.25.254.215.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user admin@westos.org
+OK
pass 123
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@mailwestos conf.d]# telnet 172.25.254.215 110
Trying 172.25.254.215...
Connected to 172.25.254.215.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user lee@westos.org
+OK
pass 123
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
使用雷鸟进行测试
注册一个新的邮箱,发一封邮件,是给你建立邮件目录
本文出自 “12100661” 博客,谢绝转载!
三.mail 接收权限 dovecot加密通信 php数据库 thunderbird