十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
建站服务器
################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源。修改主机名称
88cd /etc/sysconfig/network-scripts/
89ls
90vim 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
105logout
107vim /etc/yum.repos.d/rhel_dvd.repo
108yum clean all
#####配置DNS
109yum install bind -y
111systemctl start named
114vim /etc/named.conf
115vim /etc/named.rfc1912.zones
116cd /var/named
117ls
118cp -p named.localhostwestos.com.zone
119vim westos.com.zone
120cp -p westos.com.zoneqq.com.zone
121vim qq.com.zone
122systemctl restart named
131systemctl stop firewalld
####测试:
123vim /etc/resolv.conf
124cd
126dig dns.westos.com
136dig -t mx westos.com
二:server虚拟机(qq-mail.qq.com)
######配置网络。yum源。修改主机名称
1 cd/etc/sysconfig/network-scripts/
2ls
3vim ifcfg-eth0
4vim /etc/yum.repos.d/rhel_dvd.repo
5 yumclean all
6hostnamectl set-hostname qq-mail.qq.com
7logout
#######测试:
20vim /etc/resolv.conf
21dig dns.qq.com
22dig -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
28vim /etc/postfix/main.cf
29systemctl restart postfix.service
30systemctl 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
8vim /etc/postfix/main.cf
9 systemctl restartpostfix.service
10systemctl stop firewalld
测试:可以互相发邮件
31mail root@qq.com
32mailq
33mail
11mail
12mail root@westos.com
13mailq
3.邮件别名
[root@qq-mail ~]# vim /etc/aliases
别名: 真名 ##邮件别名
别名: :include:filename ##邮件群发
vim filename
user1
user2
postalias /etc/aliases
mail 别名
39vim /etc/aliases ####配置文件
40vim /etc/postfix/qun
41postalias /etc/aliases ###加密
42systemctl restart postfix.service
43mail qun@westos.com #####邮件群发
44mailq
45mail
46mail -u student
47mail admin@westos.com #####root别名admin
48mailq
49mail
50mail admiin@westos.com ####student别名admiin
51mailq
52mail -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
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
U1 root Tue May 2300:05 22/734 qqqq
>N 2 root@westos.com Tue May 23 01:52 14/494
N3 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
#####限制用户发送
[root@westos-mail ~]# postconf -esmtpd_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_checksmaster.cf relocated sender.dbvirtual
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
############限制用户接收
[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
quit
221 2.0.0 Bye
Connection closed by foreign host.
#########企业邮箱
####出栈地址转换
1postconf -d | grep generic
2postconf -e smtp_generic_maps =hash:/etc/postfix/generic
3vim /etc/postfix/main.cf
4vim /etc/postfix/generic
westos@westos.com hello@sb.com
真域名假域名
5postmap/etc/postfix/generic
6systemctl restart postfix
7su - westos
测试:[westos@westos-mail ~]$ history
1mail root@qq.com
2mailq
[root@qq-mail ~]# mail
##入战地址转换
1. dns mx 记录解析先做好
17vim /etc/named.rfc1912.zones
18 cp-p qq.com.zone sb.com.zone
19vim sb.com.zone
20systemctl restart named
21dig -t mx sb.com
2.
26 postconf -evirtual_alias_maps =hash:/etc/postfix/virtual
27vim /etc/postfix/main.cf
28vim /etc/postfix/virtual
虚拟名字 真实用户
hello@sb.com westos@westos.com
29postmap /etc/postfix/virtual
30systemctl restart postfix
31su - 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
15touch /etc/skel/mail/.imap/INBOX
16useradd lee
17cd /home/lee
18ll
19ls mail/ -a
20ls mail/.imap/INBOX
21passwd lee
22mail 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:
201mv /etc/postfix/main.cf /mnt/
202yum reinstall postfix -y
203vim /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 ##接收邮件结尾字符的指定
204systemctl restart postfix
(2)######mariadb####
205yum install http php php-mysql mariadb-server -y
206systemctl start mariadb
208vim /etc/my.cnf ###mysqul的配置文件
14 skip-networking=1
209systemctl restart mariadb ###重启mariadb服务
210Mysql_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
218tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
####解压压缩包到/var/www/html
219ls
220rm -fr *.bz2
221ls
222mv phpMyAdmin-3.4.0-all-languages/ mysqladmain #### 将安装包下的所有文件移动到 mysqladmin
223cd mysqladmain/
224ls
225cp config.sample.inc.phpconfig.inc.php ###复制配置文件
226vim config.inc.php ###写配置文件
$cfg[\'blowfish_secret\'] = \'mysql\'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH!*/
227systemctl restart httpd
真机:
打开浏览器访问:http://172.25.254.144/myadmin/
westos.com:
228mysql -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
34vim mailuser.cf ####用户名称查询
hosts = localhost #####数据库所在的主机
user = postuser #####登陆数据库的用户
password = postuser #####登陆数据库的密码
dbname = email #####postfix要查询的名字
table = emailuser ######postfix要查询的表的名字
select_field = username #####postfix要查询的字段
where_field = username ####用户给定postfix的查询条件
35postmap -q lee@lee.com mysql:/etc/postfix/mailuser.cf
36cp mailuser.cf maildomain.cf
37vim maildomain.cf #### 用户域名查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
38postmap -q lee.com mysql:/etc/postfix/maildomain.cf
39cp mailuser.cf mailbox.cf
40vim mailbox.cf ####用户邮箱位置查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
41postmap -q lee@lee.com mysql:/etc/postfix/mailbox.cf
42ls
43cat mailuser.cf
44cat maildomain.cf
45cat mailbox.cf
46history
二##配置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 -evirtual_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 newtmp
[root@westos-mail lee]# catnew/1495545556.Vfd01I1a9eecdM433309.westos-mail.westos.com