postfix
1 postfix提供 smtp協議用來投遞郵件
默認端口25
mail [email protected]
Subject: qwe
safsafg
adsf
. ##用“.”結束錄入併發送
EOT
mailq ##查看郵件隊列
postqueue -f ##重新處理郵件隊列
postsuper -d ** ##刪除錯的郵件
默認情況下郵件端口只在127.0.0.1上開啓
2配置
117
vim /etc/postfix/main.cf
76 myhostname = westos-mail.westos.com
83 mydomain = westos.com
99 myorigin = westos.com
116 inet_interfaces = all
164 mydestination = $myhostname, $mydomain, localhost
systemctl restart postfix.service
systemctl stop firewalld
217
vim /etc/postfix/main.cf
76 myhostname = qq-mail.qq.com
83 mydomain = qq.com
99 myorigin = qq.com
116 inet_interfaces = all
164 mydestination = $myhostname, $mydomain, localhost
systemctl restart postfix.service
systemctl stop firewalld
3郵件別名
vim /etc/aliases
別名: 真名 ##郵件別名
別名: :include:filename ##郵件羣發
vim filename
user1
user2
postalias /etc/aliases ##使文件生效
測試
mail 別名
mail [email protected]
通過遠程主機發郵件
17
yum install telnet -y
[root@dns-server Desktop]# telnet 172.25.254.117 25 ##25 端口
Trying 172.25.254.117...
Connected to 172.25.254.117.
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:[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>
adfasdgf
asdfagaa
gadgdfga
agfadfg
.
250 2.0.0 Ok: queued as C69BD2461FF
q
502 5.5.2 Error: command not recognized
^Cquit
quit ###退出
Connection closed by foreign host.
測試
217
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 5 messages 1 new 4 unread
1 root Sat May 20 03:38 23/736 "sadf"
U 2 root Sat May 20 04:11 22/735 "qw"
U 3 root Sat May 20 04:12 25/868 "wq"
U 4 root Sat May 20 04:27 25/877 "safafaf"
>N 5 [email protected] Sat May 20 04:37 16/514
& 5
Message 5:
From [email protected] Sat May 20 04:37:07 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Status: R
adfasdgf
asdfagaa
gadgdfga
agfadfg
& q
Held 5 messages in /var/spool/mail/root
您在 /var/spool/mail/root 中有郵件
> /var/spool/mail/root ##清空郵件
5 郵件客戶端的訪問控制
117
postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
###完成後會在/etc/postfix/main.cf文件最後出現680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
vim /etc/postfix/access
477 172.25.254.17 REJECT
postmap /etc/postfix/access ##加密access文件,會在/etc/postfix/生成access.db加密文件 真正讀的文件是access.db而非access
systemctl restart postfix.service
測試
17
[root@dns-server Desktop]# telnet 172.25.254.117 25
Trying 172.25.254.117...
Connected to 172.25.254.117.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied ##被拒絕
quit
221 2.0.0 Bye
Connection closed by foreign host.
##限制用戶發送
117
systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
Active: inactive (dead)
systemctl start named
postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
vim /etc/postfix/sender
[email protected] REJECT ###REJECT後不能空格,否則格式會出錯
postmap /etc/postfix/sender
systemctl restart postfix.service
測試
17
[root@dns-server 桌面]# telnet 172.25.254.117 25
Trying 172.25.254.117...
Connected to 172.25.254.117.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.
##限制用戶接收
117
postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
vim /etc/postfix/recip
useradd westos
postmap /etc/postfix/recip
systemctl restart postfix.service
測試
17
[root@dns-server 桌面]# telnet 172.25.254.117 25
Trying 172.25.254.117...
Connected to 172.25.254.117.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
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>
fasf
adsf
.
250 2.0.0 Ok: queued as 6E712EAC27
[root@dns-server 桌面]# telnet 172.25.254.117 25
Trying 172.25.254.117...
Connected to 172.25.254.117.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied
##出站地址僞裝
117
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
vim /etc/postfix/generic
[email protected] [email protected]
postmap /etc/postfix/generic
systemctl restart postfix.service
測試
su - westos
mail [email protected]
[westos@westos-mail ~]$ mail [email protected]
Subject: dstttttt
2
.
EOT
217
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 8 messages 1 new 4 unread
1 root Sat May 20 03:38 23/736 "sadf"
U 2 root Sat May 20 04:11 22/735 "qw"
U 3 root Sat May 20 04:12 25/868 "wq"
U 4 root Sat May 20 04:27 25/877 "safafaf"
5 [email protected] Sat May 20 04:37 17/525
6 [email protected] Sat May 20 22:32 22/738 "wef"
7 [email protected] Sat May 20 22:35 22/743 "gfagagagtr"
>N 8 [email protected] Sat May 20 22:46 21/713 "dstttttt"
&
##入站地址轉換
117
先準備dns mx 記錄解析
vim /etc/named.rfc1912.zones
37 zone "sb.com" IN {
38 type master;
39 file "westos.com.zone";
40 allow-update { none; };
41 };
cd /var/named/
cp -p qq.com.zone sb.com.zone
vim sb.com.zone
1 $TTL 1D
2 @ IN SOA dns.sb.com. root.sb.com. (
3 0 ; serial
4 1D ; refresh
5 1H ; retry
6 1W ; expire
7 3H ) ; minimum
8 NS dns.sb.com.
9 dns A 172.25.254.117
10 sb.com. MX 1 172.25.254.117.
systemctl restart named
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
vim /etc/postfix/virtual
虛擬名字 真實用戶
[email protected] [email protected]
postmap /etc/postfix/virtual
systemctl restart postfix.service
測試
mail [email protected]
[root@westos-mail named]# mail [email protected]
Subject: 444
12
.
EOT
[root@westos-mail named]# su - westos
上一次登錄:六 5月 20 22:55:33 EDT 2689pxs/0 上
[westos@westos-mail ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/westos": 1 message 1 new
>N 1 root Sat May 20 22:56 18/552 "444"
& quit
Held 1 message in /var/spool/mail/westos
You have mail in /var/spool/mail/westos
dovecot
1.
dovecot 用來提供收件協議
pop3 110
imap 143
imaps 993
pop3s 995
給定用戶名稱,密碼,dovecot代我們去看這個用戶的郵件
2.
217
yum install dovecot -y
17
yum imstall mutt -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@qq-mail ~]$ mkdir mail/.imap/ -p
[westos@qq-mail ~]$ touch mail/.imap/INBOX
測試
[westos@qq-mail ~]$ mail westos
Subject:
124
12
.
EOT
17
mutt -f pop://[email protected]
###在root@qq中skel建立目錄,文件 ,所有新用戶都有skel中的內容,位置/home/新用戶名
[root@qq-mail ~]# mkdir /etc/skel/mail/.imap -p
[root@qq-mail ~]# touch /etc/skel/mail/.imap/INBOX