Unit3.4 邮件管理

来源:互联网 发布:软件注册码生成器 编辑:程序博客网 时间:2024/06/10 04:32
####postfix#####

1.postfix提供smtp协议用来投递邮件
默认端口25
/var/log/maillog              ##服务日志
mail root@westos.com
Subject: hello
hello world
.                             ##用"."来结束录入内容并发送

mailq                         ##查看邮件队列

  

postqueue -f                  ##重新处理邮件队列
postsuper -d 邮件id            ##删除未发出邮件
postsuper -d ALL              ##删除所有未发出邮件

mail                          ##查看收到的邮件


mail -u 用户名                 ##查看该用户收到的邮件     
邮件序号查看邮件内容,q结束
默认情况下邮件端口只在127.0.0.1上开启

2.配置(两台测试主机都要配置)
vim /etc/postfix/main.cf
76 myhostname = westos-mail.westos.com                     ##25端口开启的网络接口

83 mydomain = westos.com                                   ##指定mta主机名称


99 myorigin = westos.com                                   ##指定mta主机域名


116 inet_interfaces = all


164 mydestination = $myhostname, $mydomain, localhost      ##指定邮件来源结尾(@后面的字符内容)


systemctl restart postfix.service

systemctl stop firewalld



3.邮件别名
vim /etc/aliases        ##收件人修改配置文件
别名:     真名    
admin:           root                            ##邮件别名

moreuser:        :include:/etc/postfix/moreuser  ##邮件群发



vim /etc/postfix/moreuser                        ##编辑群发人



postalias /etc/aliases                           ##使配置文件立即生效

systemctl restart postfix.service



测试:
westos主机

mail admin@qq.com


mail moreuser@qq.com



qq主机

mail


mail -u student



4.远程主机发送邮件
真机

yum install telnet -y


telnet 172.25.254.124 25                ##连接上124主机
ehlo hello                              ##查看是否连接
250-westos-mail.westos.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:root@westos.com               ##发件人
rcpt to:root@qq.com                     ##收件人
data                                    ##开始编辑邮件内容
354 End data with <CR><LF>.<CR><LF>
dsad
dsdsa
.
250 2.0.0 Ok: queued as 0F85CB6
quit                                    ##退出
221 2.0.0 Bye

Connection closed by foreign host.


测试:

qq主机收到邮件




5.邮件客户端的访问控制
在mta上
postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"  ##
vim /etc/postfix/main.cf              
文件最后一行多出来了

smtpd_client_restrictions = check_client_access hash:/etc/postfix/access


vim /etc/postfix/access

172.25.254.24           REJECT


postmap /etc/postfix/access           ##加密,并生成db文件

systemctl restart postfix.service


测试:
telnet 172.25.254.124 25
Trying 172.25.254.124...
Connected to 172.25.254.124.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:root@qq.com

554 5.7.1 <unknown[172.25.254.24]>: Client host rejected: Access denied



6.限制用户发送

postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postix/sender"


vim /etc/postfix/sender

student@westos.com  REJECT


postmap /etc/postfix/sender

systemctl restart postfix


测试:
telnet 172.25.254.118 25
Trying 172.25.254.118...
Connected to 172.25.254.118.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:student@westos.com
250 2.1.0 Ok
rcpt to:root@qq.com

451 4.3.5 <root@westos.com>: Sender address rejected: Access denied



7.限制用户接收

postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postix/recip"


vim /etc/postfix/recip

westos@westos.com  REJECT


postmap /etc/postfix/recip

systemctl restart postfix


测试:
telnet 172.25.254.118 25
Trying 172.25.254.118...
Connected to 172.25.254.118.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:westos@westos.com

451 4.3.5 <westos@westos.com>: Recipient address rejected: Access denied




8.出站地址伪装

postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"


vim /etc/postfix/generic

westos@westos.com hello@sb.com


postmap /etc/postfix/generic

systemctl restart postfix.service



测试:
su - westos

mail root@qq.com

qq主机mail 查看邮件



9.入站地址伪装

dns mx 记录解析要先做好


postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"


vim /etc/postfix/viryual
虚拟名字           真实用户

hello@sb.com      westos@westos.com


postmap /etc/postfix/virtual

systemctl restart postfix



vim /etc/services   ##查看端口
测试:

mail hello@sb.com

westos主机mail -u westos查看邮件

10.dovecot
1)
dovecot    用来提供收件协议
pop3       110
pop3s      995
imap       143
imaps      993
给定用户名称,用户密码,dovecot程序代我们去看这个用户的邮件文件

2)yum install dovecot -y
3)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


useradd westos
passwd westos
su - westos


[westos@westos-mail ~]$ mkdir mail/.imap/ -p
[westos@westos-mail ~]$ touch mail/.imap/INBOX
或者直接在root用户下(前面建立的用户仍然没有,后面建立的用户自动覆盖)
[root@westos-mail ~]# mkdir /etc/skel/mail/.imap -p
[root@westos-mail ~]# touch /etc/skel/mail/.imap/INBOX


测试:
yum install mutt -y

mutt -f pop://westos@172.25.254.124


11.雷鸟软件的应用
rpm -ivh /mnt/thunderbird-31.2.0-1.el7.x86_64.rpm    ##解压软件包

thunderbird    ##打开应用



12.postfix+mariadb
yum install httpd php php-mysql mariadb-server.x86_64  -y


建立数据库并进入数据库图形管理界面
创建email数据库,emailuser数据表

表中包含username,password,domain,maildir 4个字段


并插入数据

用root用户登陆数据库
create user postuser@localhost identified by 'postuser';         ##创建用户,密码
grant select,update,insert on email.* to postuser@localhost;     ##授予用户查询,更新,插入权限


cd /etc/postfix/
vim /etc/postfix/mailuser.cf        ##用户名称查询
hosts = localhost                   ##数据库所在主机
user = postuser                     ##登陆数据库的用户
password = postuser                 ##登陆数据库的密码
dbname = email                      ##postfix要查询的库的名称
table = emailuser                   ##postfix要查询的表的名称
select_field = username             ##postfix要查询的字段
where_field = username              ##用户给定postfix的查询条件



cp -p mailuser.cf maildomain.cf     ##用户域名查询
vim maildomain.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain


cp -p mailuser.cf mailbox.cf        ##用户邮箱位置查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username


测试:
postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
lee@lee.com
postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
lee.com
postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
/mnt/lee.com/lee




13.配置postfix
groupadd -g 666 vmail
useradd -s /sbin/nologin -u 666 vmail -g 666               
postconf -e "virtual_mailbox_base = /home/vmail"         ##设定虚拟用户的邮件目录
postconf -e "virtual_uid_maps = static:666"              ##虚拟用户建立邮件的uid
postconf -e "virtual_gid_maps = static:666"              ##虚拟用户建立邮件的gid
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf"
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"
systemctl restart postfix


测试:

mail lee@lee.com
ls /home/vmail/lee.com/lee/new
会发现发出去的邮件


原创粉丝点击