您好,登錄后才能下訂單哦!
(一)postfix 配置
一 配置dns
1 yum install bind -y
2 systemctl start named
3 vim /etc/named.conf
內容:
options {
// listen-on port 53 { 127.0.0.1; };
// listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
dnssec-validation no;###是否合法,即是否可以充當公網上的dns,如果沒有申請,就寫no###
4 vim /etc/named.rfc1912.zones
內容:
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "qq.com" IN {
type master;
file "qq.com.zone";
allow-update { none; };
};
5 cd /var/named/
6 cp -p named.localhost westos.com.zone
7 vim 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.112
westos.com. MX 1 172.25.254.112.
8 cp -p westos.com.zone qq.com.zone
9 vim 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.112
qq.com. MX 1 172.25.254.212.
10 systemctl restart named
11 systemctl stop firewalld.service
12 systemctl disable firewalld.service
二 基本電子郵件發送
1)postfix定義:
postfix提供smtp協議用來投遞郵件,默認端口為25,日志在/var/log/maillog
MDA:“郵件發送代理“
2)重要的Postfix配置指令
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
3)郵件發送
發送郵件端:
1 vim /etc/postfix/main.cf###編輯postfix的主配置文件###
內容:
116 inet_interfaces = all###25端口開啟的網絡接口默認情況下,Postfix僅偵聽來自本地主機的傳入電子郵件。若要重新配置postfix以接收從遠程主機發
送的本地郵件,必須設置inet_interfaces = all###
76 myhostname = westos-mail.westos.com###指定mta主機名稱###
83 mydomain = westos.com###指定mta的域名###
99 myorigin = westos.com###指定郵件來源結尾(@后面的字符內容)
164 mydestination = $myhostname, $mydomain, localhost###接受郵件結尾字符的指定#
2 systemctl restart postfix.service###重啟服務###
3 systemctl stop firewalld###關閉防火墻###
4 mail root@qq.com###發送郵件###
Subject: hello
hello
.###以“.”表示結束###
EOT
5 mailq(或postqueue -p)###顯示已排隊的所有傳出郵件的列表###
6 postqueue -f###再次立即發送所有已排隊的郵件###
接受郵件端:
1 vim /etc/postfix/main.cf
內容:
116 inet_interfaces = all ###25端口開啟的網絡接口。默認情況下,Postfix僅偵聽來自本地主機的傳入電子郵件。若要重新配置postfix以接收從遠程主機發
送的本地郵件,必須設置inet_interfaces = all###
76 myhostname = qq-mail.westos.com ###指定mta主機名稱###
83 mydomain = qq.com ###指定mta的域名###
99 myorigin = $mydomain ###指定郵件來源結尾(@后面的字符內容)
164 mydestination = $myhostname, $mydomain, localhost ###接受郵件結尾字符的指定#
2 systemctl restart postfix.service
3 systemctl stop firewalld.service
4 mail###查看獲得的郵件###
過程如下:
發郵件端:
[root@westos-mail named]# 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###指定郵件來源結尾(@后面的字符內容)
164 mydestination = $myhostname, $mydomain, localhost###接受郵件結尾字符的指定#
[root@westos-mail named]# systemctl restart postfix.service
[root@westos-mail named]# systemctl stop firewalld
[root@westos-mail named]# mail root@qq.com
Subject: hello
hello
.
EOT
[root@westos-mail named]# mailq
Mail queue is empty
[root@westos-mail named]#
接收郵件端:
[root@qq-mail ~]# vim /etc/postfix/main.cf
116 inet_interfaces = all ###25端口開啟的網絡接口###
76 myhostname = qq-mail.qq.com ###指定mta主機名稱###
83 mydomain = qq.com ###指定mta的域名###
99 myorigin = $mydomain ###指定郵件來源結尾(@后面的字符內容)
164 mydestination = $myhostname, $mydomain, localhost ###接受郵件結尾字符的指定#
[root@qq-mail ~]# systemctl restart postfix.service
[root@qq-mail ~]# systemctl stop firewalld.service
[root@qq-mail ~]# mailq
Mail queue is empty
You have mail in /var/spool/mail/root
[root@qq-mail ~]# cat /var/spool/mail/root
From root@westos.com Sat May 20 03:13:41 2017
Return-Path: <root@westos.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Received: from westos-mail.westos.com (unknown [172.25.254.112])
by qq-mail.westos.com (Postfix) with ESMTP id 3442417E84B
for <root@qq.com>; Sat, 20 May 2017 03:13:41 -0400 (EDT)
Received: by westos-mail.westos.com (Postfix, from userid 0)
id CD43D2462AE; Sat, 20 May 2017 03:13:40 -0400 (EDT)
Date: Sat, 20 May 2017 03:13:40 -0400
To: root@qq.com
Subject: hello
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
三 郵件別名
接收郵件端:
1 vim /etc/aliases
內容:
admin: root
別名 真名
2 postalias /etc/aliases###立即生效###
3 systemctl restart postfix.service###重啟服務###
測試:
發郵件端:
1 mail admin@qq.com
Subject: haa
haa
.
EOT
2 mailq
接收郵件端:
過程如下:
發郵件端:
[root@westos-mail ~]# mail admin@qq.com
Subject: haa
haa
.
EOT
[root@westos-mail ~]# mailq
Mail queue is empty
收郵件端:
[root@qq-mail ~]# vim /etc/aliases
[root@qq-mail ~]# postalias /etc/aliases ###立即生效###
[root@qq-mail ~]# systemctl restart postfix.service
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 3 messages 1 new 3 unread
U 1 root Sat May 20 03:13 22/741 "hello"
U 2 root Sat May 20 03:25 22/747 "world"
>N 3 root Sat May 20 04:09 21/731 "haa"
& q
Held 3 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
四 郵件群發
接收郵件端:
1 vim /etc/aliases
內容:
moreuser: :include:/etc/postfix/moreuser
別名
2 vim /etc/postfix/moreuser
內容:
student
root
3 postalias /etc/aliases###立即生效###
4 systemctl restart postfix.service###重啟服務###
測試:
發郵件端:
1 mail moreuser@qq.com
Subject: hello
kaa
.
EOT
2 mailq
收郵件端:
1 mail -u student ###查看student的郵件###
2 mail -u root ###查看root的郵件###
過程如下:
發郵件端:
[root@westos-mail ~]# mail moreuser@qq.com
Subject: hello
kaa
.
EOT
[root@westos-mail ~]# mailq
Mail queue is empty
[root@qq-mail ~]# vim /etc/aliases
moreuser: :include:/etc/postfix/moreuser
別名
[root@qq-mail ~]# vim /etc/postfix/moreuser
student
root
收郵件端:
[root@qq-mail ~]# postalias /etc/aliases
[root@qq-mail ~]# systemctl restart postfix.service
[root@qq-mail ~]# > /var/spool/mail/root
[root@qq-mail ~]# mail -u student ###查看student的郵件###
No mail for student
[root@qq-mail ~]# mail -u root ###查看root的郵件###
No mail for root
[root@qq-mail ~]# mail -u root
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/root": 1 message 1 new
>N 1 root Sat May 20 04:12 24/868 "hello"
& q
Held 1 message in /var/mail/root
[root@qq-mail ~]# mail -u student
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/student": 1 message 1 new
>N 1 root Sat May 20 04:12 24/871 "hello"
& q
Held 1 message in /var/mail/student
You have mail in /var/spool/mail/root
五 通過遠程主機測試郵件服務
1 telnet 172.25.254.112 25###連接172.25.254.112的25端口###
Trying 172.25.254.112...
Connected to 172.25.254.112.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
ehlo hello ###跟112主機打個招呼##
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 ###郵件從root@westos.com發送###
250 2.1.0 Ok
rcpt to:root@qq.com ###郵件發到root@qq.com###
250 2.1.5 Ok
data ###郵件內容###
354 End data with <CR><LF>.<CR><LF>
hello world
hai
. ##以“.”表示結束###
250 2.0.0 Ok: queued as EEB672462AF
六 拒絕遠程主機連接
1 postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access" #用smtpd_client_restrictions參數去檢測/etc/postfix/access,但真正檢測的是加密后的文件access.db####
2 vim /etc/postfix/main.cf
3 vim /etc/postfix/access###編輯你拒絕連接的主機###
內容:
172.25.254.12 REJECT
4 postmap /etc/postfix/access ###加密###
5 cd /etc/postfix/###加密后的文件在該目錄下###
6 systemctl restart postfix.service
測試:
telnet 172.25.254.112 25
過程如下:
[root@westos-mail ~]# postconf -d | grep client###顯示client的默認值##
broken_sasl_auth_clients = no
local_header_rewrite_clients = permit_inet_interfaces
parent_domain_matches_subdomains = debug_peer_list,fast_flush_domains,mynetworks,permit_mx_backup_networks,qmqpd_authorized_clients,relay_domains,smtpd_access_maps
postscreen_client_connection_count_limit = $smtpd_client_connection_count_limit
qmqpd_authorized_clients =
qmqpd_client_port_logging = no
relay_clientcerts =
smtpd_authorized_verp_clients = $authorized_verp_clients
smtpd_authorized_xclient_hosts =
smtpd_client_connection_count_limit = 50
smtpd_client_connection_rate_limit = 0
smtpd_client_event_limit_exceptions = ${smtpd_client_connection_limit_exceptions:$mynetworks}
smtpd_client_message_rate_limit = 0
smtpd_client_new_tls_session_rate_limit = 0
smtpd_client_port_logging = no
smtpd_client_recipient_rate_limit = 0
smtpd_client_restrictions =
unknown_client_reject_code = 450
[root@westos-mail ~]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access" #用smtpd_client_restrictions參數去檢測/etc/postfix/access,但真正檢測的是加密后的文件access.db####
[root@westos-mail ~]# vim /etc/postfix/main.cf
[root@westos-mail ~]# vim /etc/postfix/access
[root@westos-mail ~]# vim /etc/postfix/access
[root@westos-mail ~]# postmap /etc/postfix/access ###加密###
[root@westos-mail ~]# ls
anaconda-ks.cfg Documents Music Public Videos
Desktop Downloads Pictures Templates
[root@westos-mail ~]# cd /etc/postfix/
[root@westos-mail postfix]# ls
access generic master.cf virtual
access.db header_checks relocated
canonical main.cf transport
[root@westos-mail postfix]#
測試:
[root@foundation12 Desktop]# telnet 172.25.254.112 25
Trying 172.25.254.112...
Connected to 172.25.254.112.
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.12]>: Client host rejected: Access denied
q
502 5.5.2 Error: command not recognized
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@foundation12 Desktop]#
七 限制遠程主機連接用戶發送
被連接的主機:
1 postconf -d | grep sender###查看參數###
2 postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"###用smtpd_sender_restrictions參數去檢測
/etc/postfix/sender文件###
3 vim /etc/postfix/sender###編輯文件###
內容:
student@westos.com REJECT###拒絕student@westos.com用戶發送###
4 postmap /etc/postfix/sender###加密###
5 cd /etc/postfix/###加密后的文件在該目錄下
6 systemctl restart postfix.service###重啟服務###
過程如下:
[root@westos-mail ~]# postconf -d | grep sender
address_verify_sender = $double_bounce_sender
address_verify_sender_dependent_default_transport_maps = $sender_dependent_default_transport_maps
address_verify_sender_dependent_relayhost_maps = $sender_dependent_relayhost_maps
address_verify_sender_ttl = 0s
canonical_classes = envelope_sender, envelope_recipient, header_sender, header_recipient
double_bounce_sender = double-bounce
lmtp_sender_dependent_authentication = no
masquerade_classes = envelope_sender, header_sender, header_recipient
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps
sender_bcc_maps =
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =
sender_dependent_default_transport_maps =
sender_dependent_relayhost_maps =
smtp_sender_dependent_authentication = no
smtpd_reject_unlisted_sender = no
smtpd_sender_login_maps =
smtpd_sender_restrictions =
unverified_sender_defer_code = 450
unverified_sender_reject_code = 450
unverified_sender_reject_reason =
unverified_sender_tempfail_action = $reject_tempfail_action
[root@westos-mail ~]# postconf -e "smtpd_sender_restrictions = check_sender_acess hash:/etc/postfix/sender"
[root@westos-mail ~]# vim /etc/postfix/sender
[root@westos-mail ~]# postmap /etc/postfix/sender
[root@westos-mail ~]# systemctl restart postfix.service
[root@westos-mail ~]# systemctl start named
[root@westos-mail ~]# systemctl stop firewalld
[root@westos-mail postfix]# ls
access canonical header_checks master.cf sender transport
access.db generic main.cf relocated sender.db virtual
測試:
[kiosk@foundation12 Desktop]$ telnet 172.25.254.112 25
Trying 172.25.254.112...
Connected to 172.25.254.112.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:student@westos.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <unknown[172.25.254.12]>: Client host rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.
[kiosk@foundation12 Desktop]$
八 限制用戶接收
接受郵件端:
1 postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
2 vim /etc/postfix/recip
內容:
westos@westos.com REJECT###限制westos@wests.com用戶接收###
3 postmap /etc/postfix/recip ###加密###
4 systemctl restart postfix.service
過程如下:
[root@westos-mail ~]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
[root@westos-mail ~]# vim /etc/postfix/recip
westos@westos.com REJECT
[root@westos-mail ~]# postmap /etc/postfix/recip
[root@westos-mail ~]# systemctl restart postfix.service
測試:
[kiosk@foundation12 Desktop]$ telnet 172.25.254.112 25
Trying 172.25.254.112...
Connected to 172.25.254.112.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:westos@westos.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello
hello
.
250 2.0.0 Ok: queued as D00F9EAC27
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:westos@westos.com
554 5.7.1 <westos@westos.com>: Recipient address rejected: Access denied
421 4.4.2 westos-mail.westos.com Error: timeout exceeded
Connection closed by foreign host.
九 入站地址轉換
郵件發送方:
1 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
2 vim /etc/postfix/generic
3 postmap /etc/postfix/generic
westos@westos.com hello@haa.com
真實用戶虛擬用戶
4 postmap /etc/postfix/generic###加密###
測試:
su - westos
mail root@qq.com
過程如下:
郵件發送方:
[root@westos-mail ~]# postconf -d | grep generic
lmtp_generic_maps =
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps
smtp_generic_maps =
[root@westos-mail ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
[root@westos-mail ~]# vim /etc/postfix/generic
[root@westos-mail ~]# postmap /etc/postfix/generic
測試:
郵件發送方:
[root@westos-mail ~]# su - westos
[westos@westos-mail ~]$ mail root@qq.com
Subject: hello hello
hello
.
EOT
[westos@westos-mail ~]$ mailq
Mail queue is empty
郵件接收方:
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 3 messages 1 new
1 root Sat May 20 04:12 25/879 "hello"
2 root@westos.com Sat May 20 04:36 15/510
>N 3 hello@haa.com Sat May 20 22:32 21/725 "hello hello"
& 3
Message 3:
From hello@haa.com Sat May 20 22:32:21 2017
Return-Path: <hello@haa.com>###名字發生了變化###
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Date: Sat, 20 May 2017 22:32:23 -0400
To: root@qq.com
Subject: hello hello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: hello@haa.com
Status: R
hello
&
十 出站地址轉換
1) 先做dns解析:
1 vim /etc/named.rfc1912.zones
內容:
zone "haa.com" IN {
type master;
file "haa.com.zone";
allow-update { none; };
};
2 cd /var/named/
3 cp -p qq.com.zone haa.com.zone
4 vim haa.com.zone
內容:
$TTL 1D
@ IN SOA dns.haa.com. root.haa.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.haa.com.
dns A 172.25.254.112
haa.com. MX 1 172.25.254.112.##為真實名字主機的ip###
~
5 systemctl restart named
過程如下:
[root@westos-mail westos]# vim /etc/named.rfc1912.zones
zone "haa.com" IN {
type master;
file "haa.com.zone";
allow-update { none; };
};
[root@westos-mail named]# cd /var/named/
[root@westos-mail named]# ls
data named.ca named.localhost qq.com.zone westos.com.zone
dynamic named.empty named.loopback slaves
[root@westos-mail named]# cp -p qq.com.zone haa.com.zone
[root@westos-mail named]# vim haa.com.zone
$TTL 1D
@ IN SOA dns.haa.com. root.haa.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.haa.com.
dns A 172.25.254.112
haa.com. MX 1 172.25.254.112.
~
[root@westos-mail named]# systemctl restart named
2)配置
1 postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
2 vim /etc/postfix/virtual
內容:
hello@haa.com westos@westos.com
別名真名
3 postmap /etc/postfix/virtual###加密###
4 systemctl restart postfix.service
過程如下:
[root@westos-mail named]# postconf -d | grep virtual
address_verify_virtual_transport = $virtual_transport
propagate_unmatched_extensions = canonical, virtual
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps
unknown_virtual_alias_reject_code = 550
unknown_virtual_mailbox_reject_code = 550
virtual_alias_domains = $virtual_alias_maps
virtual_alias_expansion_limit = 1000
virtual_alias_maps = $virtual_maps
virtual_alias_recursion_limit = 1000
virtual_delivery_slot_cost = $default_delivery_slot_cost
virtual_delivery_slot_discount = $default_delivery_slot_discount
virtual_delivery_slot_loan = $default_delivery_slot_loan
virtual_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit
virtual_destination_concurrency_limit = $default_destination_concurrency_limit
virtual_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback
virtual_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback
virtual_destination_rate_delay = $default_destination_rate_delay
virtual_destination_recipient_limit = $default_destination_recipient_limit
virtual_extra_recipient_limit = $default_extra_recipient_limit
virtual_gid_maps =
virtual_initial_destination_concurrency = $initial_destination_concurrency
virtual_mailbox_base =
virtual_mailbox_domains = $virtual_mailbox_maps
virtual_mailbox_limit = 51200000
virtual_mailbox_lock = fcntl, dotlock
virtual_mailbox_maps =
virtual_minimum_delivery_slots = $default_minimum_delivery_slots
virtual_minimum_uid = 100
virtual_recipient_limit = $default_recipient_limit
virtual_recipient_refill_delay = $default_recipient_refill_delay
virtual_recipient_refill_limit = $default_recipient_refill_limit
virtual_transport = virtual
virtual_uid_maps =
[root@westos-mail named]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
[root@westos-mail named]# vim /etc/postfix/virtual
hello@haa.com westos@westos.com
別名真名
[root@westos-mail named]# postmap /etc/postfix/virtual###加密###
[root@westos-mail named]# systemctl restart postfix.service
測試:
郵件發送端:
1 mail hello@haa.com###發郵件###
2 mailq
郵件接收端:
過程如下:
[root@westos-mail named]# 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:42 21/719 "hai"
& 1
Message 1:
From root@qq.com Sat May 20 22:42:59 2017
Return-Path: <root@qq.com>
X-Original-To: hello@haa.com
Delivered-To: westos@westos.com
Date: Sat, 20 May 2017 22:42:58 -0400
To: hello@haa.com
Subject: hai
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@qq.com (root)
Status: R
hai
&
[root@qq-mail ~]# mail hello@haa.com###發郵件###
Subject: hai
hai
.
EOT
[root@qq-mail ~]# mailq
Mail queue is empty
[root@qq-mail ~]#
(二)dovecot配置
一 定義:
dovecot用來提供收件協議。
協議:端口:
pop3110
imap143
imaps993
pop3s995
給定用戶名稱,用戶密碼,dovecot程序帶我們去看這個用戶的郵件文件
二 配置
1 vim /etc/dovecot/dovecot.conf###誰能夠訪問并且通過驗證###
內容:
24 protocols = imap pop3 lmtp###打開收件協議###
48 login_trusted_networks = 0.0.0.0/0###允許所有人連接###
49 disable_plaintext_auth = no###支持明文###
2 vim /etc/dovecot/conf.d/10-mail.conf###帶用戶去看什么文件###
內容:
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
3 mkdir /etc/skel/mail/.imap -p###在用戶骨架文件里建立目錄,則新建的用戶均有該目錄###
4 touch /etc/skel/mail/.imap/INBOX
5 mkdir /home/westos/mail/.imap -p###如果是原先就存在的用戶,則要另外建該目錄,因為用戶骨架文件中沒有該用戶的這個目錄###
6 touch /home/westos/mail/.imap/INBOX
過程如下:
[root@westos-mail ~]# yum install dovecot -y
[root@westos-mail ~]# systemctl start dovecot
[root@westos-mail ~]# netstat -anplte | grep dovecot
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 0 92793 5989/dovecot
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 0 92769 5989/dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 0 92767 5989/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 0 92791 5989/dovecot
tcp6 0 0 :::993 :::* LISTEN 0 92794 5989/dovecot
tcp6 0 0 :::995 :::* LISTEN 0 92770 5989/dovecot
tcp6 0 0 :::110 :::* LISTEN 0 92768 5989/dovecot
tcp6 0 0 :::143 :::* LISTEN 0 92792 5989/dovecot
[root@westos-mail ~]# vim /etc/dovecot/dovecot.conf
[root@westos-mail ~]# vim /etc/dovecot/conf.d/10-mail.conf
[root@westos-mail ~]# systemctl restart dovecot.service
[root@westos-mail ~]# mkdir /etc/skel/mail/.imap -p
[root@westos-mail ~]# touch /etc/skel/mail/.imap/INBOX
[root@westos-mail ~]# passwd westos
Changing password for user westos.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@westos-mail ~]# mkdir /home/westos/mail/.imap -p
[root@westos-mail ~]# touch /home/westos/mail/.imap/INBOX
測試:
mutt -f pop://westos@172.25.254.112
三 profix+mysql
1)準備工作:
1 yum install httpd php php-mysql.x86_64 mariadb-server.x86_64 -y
2 vim /etc/my.cnf
內容:
skip-networking = 1
3 mysql_secure_installation ###數據庫初始化###
4 cd /var/www/html/
5 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
6 mv phpMyAdmin-3.4.0-all-languages/ myadmin
7 cd myadmin/
8 cp config.sample.inc.php config.inc.php
9 vim config.inc.php
10 systemctl restart httpd
11 create user postuser@localhost identified by 'postuser';
12 create db ,usermessage,dbuser
2)配置
1 cd /etc/postfix/
2 vim mailuser.cf###用戶名稱查詢###
內容:
hosts = localhost###數據庫所在主機###
user = postuser###登入數據庫的用戶###
password = postuser###登入數據庫的密碼###
dbname = email###postfix要查詢的庫的名稱###
table = emailuser###postfix要查詢的表的名稱###
select_field = username###postfix要查詢的字段###
where_field = username###用戶給定postfix的查詢條件###
3 cp mailuser.cf maildomain.cf###用戶域名查詢###
4 vim maildomain.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
5 cp mailuser.cf mailbox.cf
6 vim mailbox.cf ###用戶郵箱查詢###
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
7 postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf ###查看是否會輸出用戶名,若輸出,則說明寫對了###
8 postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
9 postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
3)postfix配置
1 groupadd -g 666 vmail
2 useradd -s /sbin/nologin -u 666 vmail -g 666
3 postconf -d | grep virtual
4 postconf -e "virtual_mailbox_base = /home/vmail"###設定虛擬用戶的郵件目錄###
5 postconf -e "virtual_uid_maps = static:666"###虛擬用戶建立文件的uid###
6 postconf -e "virtual_gid_maps = static:666"###虛擬用戶的建立文件的gid###
7 postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
8 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"
9 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/maildomain.cf"
測試是否寫對:若是存在則說明寫對了
ll /etc/postfix/mailuser.cf
ll /etc/postfix/mailbox.cf
ll /etc/postfix/maildomain.cf
測試:
mail lee@lee.com###看能否使用數據庫里的用戶發送郵件###
過程如下:
[root@westos-mail myadmin]# cd /etc/postfix/
[root@westos-mail postfix]# vim mailuser.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = username
where_field = username
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:mailuser.cf
postmap: fatal: bad string length 0 < 1: mailuser.cf_dbname =
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
[root@westos-mail postfix]# vim mailuser.cf
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
lee@lee.com
[root@westos-mail postfix]# cp mailuser.cf maildomain.cf
[root@westos-mail postfix]# vim maildomain.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
~
[root@westos-mail postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
lee.com,lee.com
[root@westos-mail postfix]# cp mailuser.cf mailbox.cf
[root@westos-mail postfix]# vim mailbox.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
postmap: warning: mysql query failed: Unknown column 'madir' in 'field list'
postmap: fatal: table mysql:/etc/postfix/mailbox.cf: query error: Success
[root@westos-mail postfix]# vim mailbox.cf
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
/mnt/lee.com/lee
[root@westos-mail 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 -d | grep virtual
address_verify_virtual_transport = $virtual_transport
propagate_unmatched_extensions = canonical, virtual
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps
unknown_virtual_alias_reject_code = 550
unknown_virtual_mailbox_reject_code = 550
virtual_alias_domains = $virtual_alias_maps
virtual_alias_expansion_limit = 1000
virtual_alias_maps = $virtual_maps
virtual_alias_recursion_limit = 1000
virtual_delivery_slot_cost = $default_delivery_slot_cost
virtual_delivery_slot_discount = $default_delivery_slot_discount
virtual_delivery_slot_loan = $default_delivery_slot_loan
virtual_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit
virtual_destination_concurrency_limit = $default_destination_concurrency_limit
virtual_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback
virtual_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback
virtual_destination_rate_delay = $default_destination_rate_delay
virtual_destination_recipient_limit = $default_destination_recipient_limit
virtual_extra_recipient_limit = $default_extra_recipient_limit
virtual_gid_maps =
virtual_initial_destination_concurrency = $initial_destination_concurrency
virtual_mailbox_base =
virtual_mailbox_domains = $virtual_mailbox_maps
virtual_mailbox_limit = 51200000
virtual_mailbox_lock = fcntl, dotlock
virtual_mailbox_maps =
virtual_minimum_delivery_slots = $default_minimum_delivery_slots
virtual_minimum_uid = 100
virtual_recipient_limit = $default_recipient_limit
virtual_recipient_refill_delay = $default_recipient_refill_delay
virtual_recipient_refill_limit = $default_recipient_refill_limit
virtual_transport = virtual
virtual_uid_maps =
[root@westos-mail ~]# postconf -e "virtual_mailbox_base = /home/vmail"
[root@westos-mail ~]# postconf -e "virtual_uid_maps = static:666"
[root@westos-mail ~]# postconf -e "virtual_gid_maps = static:666"
[root@westos-mail ~]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
[root@westos-mail ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfi/maildomain.cf
[root@westos-mail ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"
[root@westos-mail ~]# ll /etc/postfix/mailuser.cf
-rw-r--r--. 1 root root 134 May 21 04:06 /etc/postfix/mailuser.cf
[root@westos-mail ~]# ll /etc/postfix/mailbox.cf
-rw-r--r--. 1 root root 133 May 21 04:21 /etc/postfix/mailbox.cf
[root@westos-mail ~]# ll /etc/postfix/maildomain.cf
-rw-r--r--. 1 root root 130 May 21 04:19 /etc/postfix/maildomain.cf
[root@westos-mail ~]# cd /home/vmail/
[root@westos-mail vmail]# ls
[root@westos-mail vmail]# mail lee@lee.com
Subject: hello
hello hello
.
EOT
[root@westos-mail vmail]# mailq
Mail queue is empty
[root@westos-mail vmail]# ls
lee.com mail
[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]# cd new/
[root@westos-mail new]# cat new/
cat: new/: No such file or directory
[root@westos-mail new]# cd ne
-bash: cd: ne: No such file or directory
[root@westos-mail new]# cd new/
-bash: cd: new/: No such file or directory
[root@westos-mail new]#
[root@westos-mail new]# ls
1495357341.Vfd01I30059aaM65037.westos-mail.westos.com
[root@westos-mail new]# cat 1495357341.Vfd01I30059aaM65037.westos-mail.westos.com
Return-Path: <root@westos.com>
X-Original-To: lee@lee.com
Delivered-To: lee@lee.com
Received: by westos-mail.westos.com (Postfix, from userid 0)
id DF62F273AC2; Sun, 21 May 2017 05:02:20 -0400 (EDT)
Date: Sun, 21 May 2017 05:02:20 -0400
To: lee@lee.com
Subject: hello
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20170521090220.DF62F273AC2@westos-mail.westos.com>
From: root@westos.com (root)
hello hello
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。