首页 > 代码库 > 虚拟用户邮件传输
虚拟用户邮件传输
smtp虚拟用户邮件传输及管理
一.对简单的邮件传输进行本地管理
1).本机如何拒绝其他指定ip主机远程发送邮寄
服务器配置:(限制规则是按照查询的顺序进行的,第一条符合条件的规则被执行)
vim /etc/postfix/access
(ip)172.25.254.*** REJECT
postmap /etc/postfix/access
postconf -e "smtpd_client_restrictions =check_client_access hash:/etc/postfix/access"
systemctl restart postfix.service
测试远程发送邮件
telnet ip
mail from:westos@westos.com
rcpt to:westos@westos.com
如果远程发送邮件,客户端的ip地址符合access中的ip则拒绝该客户端的连接请求)
2).如何拒绝其他用户远程访问发送邮件
vim /etc/postfix/sender
westos@westos.com REJECT (备注:远程访问是全域名拒绝)
postmap /etc/postfix/sender
postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
systemctl restart postfix.service
3).如何指定用户不能接收远程邮件
vim /etc/postfix/recip
westos@westos.com REJECT
postmap recip
postconf -e "smtpd_recipient_restrictions =check_recipient_access hash:/etc/postfix/recip"
systemctl restart postfix.service
二.简单邮件的接收(远程接收(dovecot)管理)
1)yum install dovecot -y
查看dovecot支持的邮件类型所对应的接口(dovecot可以开启四个端口)
imap 143 cat /etc/services | grep imap
pop 110 cat /etc/services | grep imaps
imaps 993 cat /etc/services | grep pop3
pop3s 995 cat /etc/services | grep pop3s
2)vim /etc/dovecot/dovecot.conf
24| protocols = imap pop3 lmtp /*邮电传输协议 lmtp是本地传输
48| login_trusted_networks = 0.0.0.0/0
49| disable_plaintext_auth = no /*允许明文密码验证
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = mbox:~/mail:INBOX=/var/mail/%u /*本地的邮件位置
systemctl start dovecot
netstat -antlpe | grep dovecot /*查看dovecot的端口
yum install mutt -y
> /var/log/maillog
tail -f /var/log/maillog /*邮件报错信息
mutt -f pop://westos@172.25.254.200
直接进行访问会出错,没有/home/westos/mail/.imap这个目录
su - westos
cd mail
ls -a
mkdir .imap
touch /home/westos/mail/.imap/INBOX
如果想要自动建立以上的目录,需要在/etc/skel下面建立mkdir -p mail/.imap
touch /etc/skel/mail/.imap/INBOX
3).安装软件管理dovecot,雷鸟软件(安装雷鸟有两种方法,一种是写脚本,一步步安装,另外一种是建立第三方yum源
)
1)建立脚本
#!/bin/bash
yum whatprovide */$1
./thunderbird(执行雷鸟可以查看缺少的插件)执行脚本产看需要安装的软件,解决雷鸟的依赖性
三.建立简单邮件的虚拟用户和数据库关联
1)先制作php软件管理mariadb
yum install mariadb -y
yum install mariadb-server -y
yum intsall php php-mysql -y /*PHP 是一种嵌入在 HTML 并由服务器解释的脚本语言
tar jxf phpmyadmin-3.4.0-all-languages.tar.bz2 -c /var/www/html
yum install phpmyadmin-3.4.0-all-languages -y
cp config.sample.inc.php config.inc.php
vim config.inc.php
$cfg[‘blowfish_secret‘] = ‘westos‘;
systemctl restart httpd /*备注:如果不能正常重启,修改hosts的内容,加上本地dns和域名
2)安装数据库做以下设置
mysql -uroot -pwestos
select * from email.muser;
create user postfix@localhost identified by ‘postfix‘
grant insert,upddate,select on email.* to postfix@localhost;
mysql -upostfix -ppostfix
select * from email.muser;
3)编辑文件写明域名,用户名,邮件位置
cd /etc/postfix
vim mysql-users.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = muser
select_field = username
where_field = username
postmap -q "admin@linux.org" mysql:/etc/postfix/mysql-users.cf
cp -p mysql-users.cf mysql-domain.cf
修改最后两项
select_field = domain
where_field = domain
postmap -q "linux.org" mysql:/etc/postfix/mysql-domain.cf
cp -p mysql-users.cf mysql-maildir.cf
修改最后两项
select_field = maildir
where_field = username
postmap -q "admin@linux.org" mysql:/etc/postfix/mysql-maildir.cf
4)设置账号管理虚拟用户
useradd -u 666 -g 666 vmail -s /sbin/nologin
groupadd -g 666 vmail
postconf -e "virtual_gid_maps = static:666"
postconf -e "virtual_uid_maps = static:666"
postconf -e "virtual_mailbox_base = /home/vmail"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf"
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf"
5)将虚拟用户和postfix关联
cd /usr/share/doc/dovecot-2.2.10/
cd example-config
cp dovecot-sql.conf.ext /etc/dovecot
vim /etc/dovecot/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‘
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
vim /etc/dovecot/conf.d/10-auth.conf
122|!include auth-systemctl.conf.ext /*真实用户可以登录
123|!include auth-sql.conf.ext /*允许虚拟用户进行登陆
yum install dovecot-mysql.x86_64 -y
四、空壳电子邮件服务器
vim /etc/named.rfc1912.zones
znoe "linux.org" IN {
type master;
file "linux.org.zone"
allow-update { none;};
};
vim /var/named/linux.org.zone
linux.org. MX 1 172.25.254.150.
rm -fr /etc/postfix/main.cf
yum reinstall postfix -y
vim /etc/postfix/main.cf
75|myhostname = mail.mail.com
83|mydomain = mail.com
98|myorigin = linux.org
113|inet_interfaces = all
164|mydestination =
313|relayhost = 172.25.254.249
140|local_transport = error:local delivery disabled
mynetwork = 172.25.254.0/24
在核心处理邮件服务器上测试:cd /home/vmail
watch -n 1 ls /*产看发送的邮件
虚拟用户邮件传输