##################郵件服務器######################
郵件發送
smtp 協議
需要各種服務來提供該協議
接受方pop協議,imap協議
dovecot服務
作用爲提供用戶驗證
1.重置虛擬機,更改ip,主機名 ,配置yum源倉庫,關閉火牆和selinux,安裝bind服務
在desktop中
yum install bind -y
hostnamectl set-hostname ***********
vim /etc/yum.repo.d/rhel_dvd.repo
vim /etc/named.conf
註釋:11 // listen-on port 53 { 127.0.0.1; };
12 // listen-on-v6 port 53 { ::1; };
17 // allow-query { localhost; };
修改: 32 dnssec-validation no;
cd /var/named
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
};
cp -p named.localhost westos.com.zone
vim westos.com.zone
[root@mailwestos named]# cat westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.139
westos.com. MX 1 172.25.254.139.
#############################################
cp -p westos.com.zone linux.com.zone
[root@mailwestos named]# cat linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.139
linux.com. MX 1 172.25.254.239.
測試:dig -t mx westos.com//linux.com
######發郵件#########
兩個虛擬機配置一樣
smtp服務
vim /etc/postfix/main.cf
76 myhostname = mailwestos.westos.com ##配置主機名
83 mydomain = westos.com ##配置域名
99 myorigin = $mydomain ##配置炮灰域名
113 inet_interfaces = all ##打開所有的接口
114 #inet_interfaces = $myhostname
115 #inet_interfaces = $myhostname, localhost
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost ##配置可以接收哪樣的郵件
mailq ##查看當前郵箱隊列
postquene -f ##刷新郵箱隊列,將原來未能成功發送的重新發送一遍
> /var/spool/mail/root ##清空郵件箱
postsuper -d 郵件編碼 ##刪除郵件隊列
mynetworks:允許哪一臺主機把它要處理的文件發送給你
mail ##查看郵件
systemctl restart postfix ##重啓服務
###########別名和羣發##############
1.空殼郵件
vim /etc/aliases
97 admin: root ##root的別名爲admin
98 more: :include:/etc/postfix/users ##羣發
vim /etc/postfix/users
root
student
:wq
postalias /etc/aliases ##給aliases文件加密
systemctl restart postfix.service
測試:mail [email protected]
mail more ##羣發
mail -u student ##查看student的郵件
這樣在linux中並沒有admin用戶,依然可以接收到郵件
####僞裝用戶名和域名######在企業中大多這樣操作,可以僞裝自己的域名和用戶名
##linux中操作#####算作企業發送郵件
vim /etc/postfix/virtual ##配置文件
295 [email protected] [email protected] ##僞裝指定域名指定用戶
296 @qq.com @linux.com ##僞裝域名
postmap /etc/postfix/virtual ##對文件進行加密
postconf -d | grep virtual
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
測試:mail [email protected]
mail [email protected]
test
test
.
EOT
測試:mail [email protected]
mail [email protected]
Subject: qq
com
.
EOT
########在westos裏面操作#####算作企業回覆郵件
cp -p linux.com.zone qq.com.zone
$TTL 1D
@ IN SOA dns.qq.com. root.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.qq.com.
dns A 172.25.254.139
qq.com. MX 1 172.25.254.239.
vim /etc/named.rfc1912.zones
zone "qq.com" IN {
type master;
file "qq.com.zone";
allow-update { none; };
};
systemctl restart named
測試:[email protected]
#######返回者的信息更改#######
在linux中做的操作
vim generic
[email protected] [email protected]
postconf -d | grep generic
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
postmap generic ##加密
systemctl restart postfix.service
這樣mail發送郵件後,在另一邊顯示爲qq.com發來的郵件
#########devocte############
###telnet##########遠程郵件
yum install telnet -y
telnet 172.25.254.239 25 ##遠程發送郵件
[root@foundation39 ~]# telnet 172.25.254.239 25
Trying 172.25.254.239...
Connected to 172.25.254.239.
Escape character is '^]'.
220 maillinux.linux.com ESMTP Postfix
ehlo hello
250-maillinux.linux.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
kj
jk
.
250 2.0.0 Ok: queued as E223626CE00
quit
221 2.0.0 Bye
Connection closed by foreign host.
###接收郵件####
首先在239裏面安裝dovecot服務
yum install dovecot -y
86 vim /etc/dovecot/dovecot.conf
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0 ##允許訪問網絡地址 0.0.0.0/0意思爲ip可以和給定的任意不匹配
49 disable_plaintext_auth =no ##開啓明文認證
87 vim /etc/dovecot/conf.d/10-mail.conf
> 30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
mkdir /home/student/mail/.imap/
touch ./INBOX
然後在真機裏面安裝mutt軟件
yum insatll mutt -y
然後mutt -f pop://[email protected] ##直接查看郵件 只能查看student的不能查看root的
必須要在239中建立了目錄和文件後才能查看
rpm -ivh thunderbird-31.2.0-1.el7.x86_64.rpm ##安裝雷鳥
thunderbird
然後就進入客戶端了
**********#新建的用戶會自動建立skel下的目錄到自己的家目錄 ************
#######郵件和數據庫(虛擬用戶郵件)#########
先安裝數據庫等
yum install mariadb-server httpd php php-mysql -y
vim /etc/my.cnf
skip-networking=1
mysql_secure_installation
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages/ admin
cp config.sample.inc.php config.inc.php
vim config.inc.php
$cfg['blowfish_secret'] = 'test';
mysql -uroot -p
create user postfix@localhost identified by 'postfix'; ##創建用戶
grant insert,select on email.* to postfix@localhost; ##授權
重啓httpd和mariadb
測試:172.25.254.239/mysqladmin
先用root登陸然後創建數據庫和創建表 然後添加數據
接着退出之後再創建數據庫用戶和授權 然後測試用創建的用戶能不能登陸進去
cd /etc/postfix
[root@maillinux postfix]# cat mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailsql
select_field = username
where_field = username
cp mysql-user.cf mysql-domain.cf
vim mysql-domain.cf
[root@maillinux postfix]# cat mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailsql
select_field = domain
where_field = domain
cp mysql-user.cf mysql-mailbox.cf
vim mysql-mailbox.cf
[root@maillinux postfix]# cat mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailsql
select_field = maildir
where_field = username
測試: postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf
postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf
postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
postconf -d | grep virtual
[root@maillinux postfix]# postconf -e "virtual_mailbox_base = /home/vmail"
[root@maillinux postfix]# postconf -e "virtual_gid_maps = static:888"
[root@maillinux postfix]# postconf -e "virtual_uid_maps = static:888"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
ls -l /etc/postfix/mysql-user.cf
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
ls -ld /etc/postfix/mysql-domain.cf
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-domain.cf"
ls -ld /etc/postfix/mysql-mailbox.cf
先刪掉以前做的hash那兩行
680 virtual_mailbox_base = /home/vmail ##默認目錄
681 virtual_gid_maps = static:888
682 virtual_uid_maps = static:888
683 virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf
684 virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf
685 virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf
groupadd -g 888 vmail
useradd -u 888 -g 888 vmail
cd /etc/skel
mkdir mail/.imap
touch INBOX
mail [email protected]
然後cd /home/vmail/mail/redhat.com/new ##查看郵件
#######接收郵件#########
yum install dovecot-mysql.x86_64 -y
vim /etc/dovecot/dovecot.conf
48 login_trusted_networks = 0.0.0.0/0 #允許任意訪問網絡
49 disable_plaintext_auth = no #開始明文認證
vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##開啓數據庫數據認證
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
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 mailsql WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailsql WHERE username = '%u'
vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n ##郵件目錄
setsebool -P mysql_connect_any on ##打開selinux服務
配置好了之後我們在真機裏面
telnet 172.25.254.239 110
Trying 172.25.254.239..
Connected to 172.25.254.239.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user [email protected]
+OK
pass 123
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
然後在數據庫裏面插入一組數據
最後打開雷鳥 新建用戶
然後嘗試發送郵件