################email#######
基本电子邮件发送
电子邮件发送
1 .服务器使用SMTP协议将电子邮件提交至TCP端口25,或由本地客户端通过/usr/bin/sendmail程序进行提交。如果该MTA是最终目标位置,邮件将传递至MDA。否则,将使用MX记录在DNS中查找下一个MTA,并使用SMTP进行转发。
2 .MDA:“邮件发送代理”。MDA将邮件发送至收件人的本地邮件存储位置(默认情况下是/var/spool/mail/user)。Postfix提供自己的MDA,以发送至基于文件的本地默认邮件存储位置/usr/libexec/postfix/local.
3 .转发:电子邮件服务器(MTA)将提交的邮件转发至另一个服务器,以进行发送
4 .排队:失败的发送或转发尝试排队等待,并由MTA定义重试。(默认情况下,Postfix每小时执行此操作一次)
5 .拒绝:在首次提交期间,电子邮件被电子邮件服务器拒绝
6 .退回:远程服务器接受电子邮件以进行发送以后,又将该电子邮件退回给始发电子邮件服务器和/或用户
7 .电子邮件以进行发送以后,又将该电子邮件退回给始发电子邮件服务器和/或用户准备:
########################准备:#####
一: desktop虚拟机(westos-mail.westos.com)
#######配置网络。yum源。修改主机名称
88 cd /etc/sysconfig/network-scripts/
89 ls
90 vim ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.144
NETMASK=255.255.255.0
104 hostnamectl set-hostnamewestos-mail.westos.com
105 logout
107 vim /etc/yum.repos.d/rhel_dvd.repo
108 yum clean all
#####配置DNS
109 yum install bind -y
111 systemctl start named
114 vim /etc/named.conf
115 vim /etc/named.rfc1912.zones
116 cd /var/named
117 ls
118 cp -p named.localhostwestos.com.zone
119 vim westos.com.zone
120 cp -p westos.com.zoneqq.com.zone
121 vim qq.com.zone
122 systemctl restart named
131 systemctl stop firewalld
####测试:
123 vim /etc/resolv.conf
124 cd
126 dig dns.westos.com
136 dig -t mx westos.com
二:server虚拟机(qq-mail.qq.com)
######配置网络。yum源。修改主机名称
1 cd/etc/sysconfig/network-scripts/
2 ls
3 vim ifcfg-eth0
4 vim /etc/yum.repos.d/rhel_dvd.repo
5 yumclean all
6 hostnamectl set-hostname qq-mail.qq.com
7 logout
#######测试:
20 vim /etc/resolv.conf
21 dig dns.qq.com
22 dig -t mx qq.com
#######################
#### postfix ##########
1.
postfix提供smtp协议用来投递邮件
默认端口25
/var/log/maillog ##服务日志
mail root@westos.com
Subject: hello
hello world
. #用"."来结束录入内容并发送
mailq ##查看邮件队列
postqueue -f ##重新处理邮件队列
默认情况下邮件端口只在127.0.0.1上开启
2.配置 两个虚拟机都配置
可以在/etc/postfix/main.cf文件中找到以下所有指令。
(1)myorigin
重写本地发布的电子邮件,使其显示为来自该域。这样有助于确保响应返回入站邮件服务器默认:myorigin = $myhostname
(2)inet_interfaces
控制Postfix侦听传入电子邮件的网络接口。如果设置为loopback-only,仅侦听127.0.0.1和::1,
如果设置为all,则侦听所有网络接口。还可以指定特定地址。
默认:inet_interfaces = localhost
(3)mydestination
收到地址为这些域的电子邮件将传递至MDA,以进行本地发送。
默认:mydestination = $myhostname, localhost.$mydomain,localhost
(4)mynetworks
IP地址和网络的逗号分隔列表(采用CIDR表示法)。这些地址和网络可以通过此MTA转发至
任何位置,无需进一步身份验证。
默认:mynetworks = 127.0.0.0/8
(5)relayhost
relayhost转发所有通过的出站邮件。通常用方括号指定,以阻止MX记录查找。
默认:relayhost =local_transport
收件地址为$mydestination的邮件的发送方式。默认情况下,设置为local:$myhostname(使用Local MDA将传入电子邮件发送到/var/spool/mail中的本地邮件存储位置)
默认:local_transport = local:$myhostname
(6)postconf -d 显示默认值。
(7)postconf -n显示不同于默认值的更改。
####westos.com:
vim /etc/postfix/main.cf
116 inet_interfaces = all ##25端口开启的网络接口
76 myhostname = westos-mail.westos.com ##指定mta主机名称
83 mydomain = westos.com ##指定mta的域名
99 myorigin = westos.com/$mydomain ##指定邮件来源结尾(@后面的字符内容)
164 mydestination = $myhostname, $mydomain, localhost ##接收邮件结尾字符的指定
systemctl restart postfix.service
systemctl stop firewalld
28 vim /etc/postfix/main.cf
29 systemctl restart postfix.service
30 systemctl stop firewalld
####qq.com:
vim /etc/postfix/main.cf
116 inet_interfaces = all ##25端口开启的网络接口
76 myhostname = qq-mail.qq.com ##指定mta主机名称
83 mydomain = qq.com ##指定mta的域名
99 myorigin = qq.com/$mydomain ##指定邮件来源结尾(@后面的字符内容)
164 mydestination = $myhostname, $mydomain, localhost ##接收邮件结尾字符的指定
systemctl restart postfix.service
systemctl stop firewalld
8 vim /etc/postfix/main.cf
9 systemctl restartpostfix.service
10 systemctl stop firewalld
测试: 可以互相发邮件
31 mail root@qq.com
32 mailq
33 mail
11 mail
12 mail root@westos.com
13 mailq
3.邮件别名
[root@qq-mail ~]# vim /etc/aliases
别名: 真名 ##邮件别名
别名: :include:filename ##邮件群发
vim filename
user1
user2
postalias /etc/aliases
mail 别名
39 vim /etc/aliases ####配置文件
40 vim /etc/postfix/qun
41 postalias /etc/aliases ###加密
42 systemctl restart postfix.service
43 mail qun@westos.com #####邮件群发
44 mailq
45 mail
46 mail -u student
47 mail admin@westos.com #####root别名admin
48 mailq
49 mail
50 mail admiin@westos.com ####student别名admiin
51 mailq
52 mail -u student
4.通过远程主机测试邮件服务
真机:
[root@foundation44 ~]# yum install telnet.x86_64 -y
[root@foundation44 ~]# telnet 172.25.254.144 25
Trying 172.25.254.144...
Connected to 172.25.254.144.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
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 #####发送方
250 2.1.0 Ok
rcpt to:root@qq.com #####接收方
250 2.1.5 Ok
data ####编辑邮件内容
354 End data with <CR><LF>.<CR><LF>
fhylkhhiplu.kj
.
250 2.0.0 Ok: queued as 4CF3617E86E
quit #####退出
221 2.0.0 Bye
Connection closed by foreign host.
[root@foundation44 yum.repos.d]#
检测:
(1)westos.com 发送方
[root@westos-mail ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
52431246202 194 Tue May 2301:48:23 root@westos.com
(connect to172.25.254.244[172.25.254.244]:25: No route to host)
root@qq.com
-- 0 Kbytes in 1 Request.
[root@westos-mail ~]# postqueue -f ##重新处理邮件队列
[root@westos-mail ~]# mailq
Mail queue is empty
[root@westos-mail ~]#
(2)qq.com 接收方
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type? for help.
"/var/spool/mail/root": 3 messages 2 new 3 unread
U 1 root Tue May 2300:05 22/734 "qqqq"
>N 2 root@westos.com Tue May 23 01:52 14/494
N 3 root@westos.com Tue May 2301:53 15/497
& quit
Held 3 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[root@qq-mail ~]#
5.邮件客户端的访问控制
#########限制客户端
在westos.com:
postconf -e "smtpd_client_restrictions = check_client_accesshash:/etc/postfix/access" ###生成/etc/postfix/main.cf文件中的内容
vim /etc/postfix/main.cf
vim /etc/postfix/access
172.25.254.44 REJECT
postmap /etc/postfix/access ####加密/etc/postfix/access
systemctl restart postfix ####重启postfix
测试:真机
[root@foundation44 ~]# telnet 172.25.254.144 25
Trying 172.25.254.144...
Connected to 172.25.254.144.
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.44]>: Client host rejected: Accessdenied
#####限制用户发送
[root@westos-mail ~]# postconf -e"smtpd_sender_restrictions = check_sender_accesshash:/etc/postfix/sender"
[root@westos-mail ~]# vim /etc/postfix/main.cf
[root@westos-mail ~]# vim /etc/postfix/sender
student@westos.com REJECT
[root@westos-mail ~]# cd /etc/postfix
[root@westos-mail postfix]# ls
access canonical header_checks master.cf relocated sender.db virtual
access.db generic main.cf qun sender transport
[root@westos-mail postfix]# systemctl start named
[root@westos-mail postfix]# systemctl restart postfix
测试:
[root@foundation44 ~]# telnet 172.25.254.144 25
Trying 172.25.254.144...
Connected to 172.25.254.144.
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
554 5.7.1 <student@westos.com>: Sender address rejected: Accessdenied
############限制用户接收
[root@westos-mail ~]# postconf -e "smtpd_recipient_restrictions =check_sender_access hash:/etc/postfix/recip"
[root@westos-mail ~]# vim /etc/postfix/main.cf
[root@westos-mail ~]# vim /etc/postfix/recip
westos@westos.com REJECT
[root@westos-mail ~]# postmap /etc/postfix/recip
[root@westos-mail ~]# systemctl restart postfix
[root@westos-mail ~]# useradd westos
[root@westos-mail ~]#
测试:
[root@foundation44 ~]# telnet 172.25.254.144 25
Trying 172.25.254.144...
Connected to 172.25.254.144.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:westos@westos.com
250 2.1.0 Ok
rcpt to:westos@westos.com
554 5.7.1 <westos@westos.com>: Sender address rejected: Accessdenied
quit
221 2.0.0 Bye
Connection closed by foreign host.
#########企业邮箱
####出栈地址转换
1 postconf -d | grep generic
2 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
3 vim /etc/postfix/main.cf
4 vim /etc/postfix/generic
westos@westos.com hello@sb.com
真域名 假域名
5 postmap /etc/postfix/generic
6 systemctl restart postfix
7 su - westos
测试:[westos@westos-mail ~]$ history
1 mail root@qq.com
2 mailq
[root@qq-mail ~]# mail
##入战地址转换
1. dns mx 记录解析先做好
17 vim /etc/named.rfc1912.zones
18 cp-p qq.com.zone sb.com.zone
19 vim sb.com.zone
20 systemctl restart named
21 dig -t mx sb.com
2.
26 postconf -e"virtual_alias_maps = hash:/etc/postfix/virtual"
27 vim /etc/postfix/main.cf
28 vim /etc/postfix/virtual
虚拟名字 真实用户
hello@sb.com westos@westos.com
29 postmap /etc/postfix/virtual
30 systemctl restart postfix
31 su - westos
测试:
[root@qq-mail ~]# mail hello@sb.com
[westos@westos-mail ~]$ mail
##########################
####### dovecot ##########
##########################
1.
dovecot 用来提供收件协议
pop3 110
imap 143
imaps 993
pop3s 995
给定用户名称,用户密码,dovecot程序代我们去看这个用户的邮件文件
###############收邮件######
2.
yum install dovecot -y
systemctl start dovecot
netstat -antlpe | grep dovecot
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 ##防止别人收到你的邮件
passwd westos ####
mail westos
4.
[root@westos-mail ~]# su - westos
[westos@westos-mail ~]$ mkdir mail/.imap/ -p
[westos@westos-mail ~]$ touch mail/.imap/INBOX
[westos@westos-mail ~]$ logout
5.自动撰写 mail/.imap
mkdir /etc/skel/mail/.imap/ -p
touch /etc/skel/mail/.imap/INBOX
/etc/skel #####骨架目录
14 mkdir /etc/skel/mail/.imap/ -p
15 touch /etc/skel/mail/.imap/INBOX
16 useradd lee
17 cd /home/lee
18 ll
19 ls mail/ -a
20 ls mail/.imap/INBOX
21 passwd lee
22 mail lee
测试
真机:
[root@foundation44 ~]# yum install mutt -y
[root@foundation44 ~]# mutt -fpop://westos@172.25.254.144
2 kept, 0 deleted.
[root@foundation44 ~]# mutt -fpop://lee@172.25.254.144
1 kept, 0 deleted.
选择O
输入密码
按Enter
######雷鸟######
1 下载 thunderbird-31.2.0-1.el7.x86_64.rpm
2 安装
yum install /home/kiosk/Desktop/thunderbird-31.2.0-1.el7.x86_64.rpm -y
3 (1)打开雷鸟
(2)
4验证:
[root@qq-mail ~]# mail
##########mariadb;dovecot;postfix########
一
准备工作:
(1)#####postfix###
westos.com:
201 mv /etc/postfix/main.cf /mnt/
202 yum reinstall postfix -y
203 vim /etc/postfix/main.cf
116 inet_interfaces = all ##25端口开启的网络接口
76 myhostname = qq-mail.qq.com ##指定mta主机名称
83 mydomain = qq.com ##指定mta的域名
99 myorigin = qq.com/$mydomain ##指定邮件来源结尾(@后面的字符内容)
164 mydestination = $myhostname, $mydomain, localhost ##接收邮件结尾字符的指定
204 systemctl restart postfix
(2)######mariadb####
205 yum install http php php-mysql mariadb-server -y
206 systemctl start mariadb
208 vim /etc/my.cnf ###mysqul的配置文件
14 skip-networking=1
209 systemctl restart mariadb ###重启mariadb服务
210 mysql_secure_installation ###mysql安全内容配置
所有都按Enter键
下载
215 scproot@172.25.254.44:/home/kiosk/Desktop/phpMyAdmin-3.4.0-all-languages.tar.bz2 /var/www/html
###########下载 压缩包
216 cd /var/www/html
217 ls
218 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
####解压压缩包到/var/www/html
219 ls
220 rm -fr *.bz2
221 ls
222 mv phpMyAdmin-3.4.0-all-languages/ mysqladmain #### 将安装包下的所有文件移动到 mysqladmin
223 cd mysqladmain/
224 ls
225 cp config.sample.inc.php config.inc.php ###复制配置文件
226 vim config.inc.php ###写配置文件
$cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH!*/
227 systemctl restart httpd
真机:
打开浏览器访问:http://172.25.254.144/myadmin/
westos.com:
228 mysql -uroot -pqwer
MariaDB [(none)]> create userpostuser@localhost identified by 'postuser'; ####建立postuser用户 ,本地登陆
MariaDB [(none)]> grantselect,update,insert on email.* to postuser@localhost; ####### 本机登陆postuser,授权
MariaDB [(none)]> select * fromemail.emailuser;###查询email.emailuser表中的所有内容
MariaDB [(none)]> quit
测试:
32 cd /etc/postfix
34 vim mailuser.cf ####用户名称查询
hosts = localhost #####数据库所在的主机
user = postuser #####登陆数据库的用户
password = postuser #####登陆数据库的密码
dbname = email #####postfix要查询的名字
table = emailuser ######postfix要查询的表的名字
select_field = username #####postfix要查询的字段
where_field = username ####用户给定postfix的查询条件
35 postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
36 cp mailuser.cf maildomain.cf
37 vim maildomain.cf #### 用户域名查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
38 postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
39 cp mailuser.cf mailbox.cf
40 vim mailbox.cf ####用户邮箱位置查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
41 postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
42 ls
43 cat mailuser.cf
44 cat maildomain.cf
45 cat mailbox.cf
46 history
二##配置postfix
[root@westos-mail ~]# groupadd -g 666 vmail
[root@westos-mail ~]# useradd -s /sbin/nologin -u 666 vmail -g 666
[root@westos-mail ~]# id vmail
uid=666(vmail) gid=666(vmail) groups=666(vmail)
[root@westos-mail ~]# postconf -e "virtual_mailbox_base =/home/vmail"
##设定虚拟用户的邮件目录
[root@westos-mail ~]# postconf -e"virtual_uid_maps = static:666"
##虚拟用户建立文件的uid
[root@westos-mail ~]# postconf -e "virtual_gid_maps =static:666"
##虚拟用户建立文件的gid
[root@westos-mail ~]# postconf -e "virtual_alias_maps =mysql:/etc/postfix/mailuser.cf"
[root@westos-mail ~]# postconf -e "virtual_mailbox_domains =mysql:/etc/postfix/maildomain.cf"
[root@westos-mail ~]# postconf -e "virtual_mailbox_maps =mysql:/etc/postfix/mailbox.cf"
[root@westos-mail ~]# vim/etc/postfix/main.cf
[root@westos-mail ~]# systemctl restartpostfix
[root@westos-mail ~]# ll/etc/postfix/mailbox.cf
-rw-r--r--. 1 root root 134 May 23 09:05 /etc/postfix/mailbox.cf
[root@westos-mail ~]# ll /etc/postfix/mailuser.cf
-rw-r--r--. 1 root root 135 May 23 09:03 /etc/postfix/mailuser.cf
[root@westos-mail ~]# ll /etc/postfix/maildomain.cf
-rw-r--r--. 1 root root 131 May 23 09:04 /etc/postfix/maildomain.cf
修改邮箱位置
测试:
[root@westos-mail ~]# cd /home/vmail
[root@westos-mail vmail]# ls
[root@westos-mail vmail]# mail lee@lee.com
Subject: abcd
abcd
.
EOT
[root@westos-mail vmail]# ls
lee.com
[root@westos-mail vmail]# cd lee.com
[root@westos-mail lee.com]# ls
lee
[root@westos-mail lee.com]# cd lee
[root@westos-mail lee]# ls
cur new tmp
[root@westos-mail lee]# catnew/1495545556.Vfd01I1a9eecdM433309.westos-mail.westos.com
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。