(一)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 [email protected]###发送邮件###
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###查看获得的邮件###
过程如下:
发邮件端:
[[email protected] 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###接受邮件结尾字符的指定#
[[email protected] named]# systemctl restart postfix.service
[[email protected] named]# systemctl stop firewalld
[[email protected] named]# mail [email protected]
Subject: hello
hello
.
EOT
[[email protected] named]# mailq
Mail queue is empty
[[email protected] named]#
接收邮件端:
[[email protected] ~]# 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 ###接受邮件结尾字符的指定#
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# mailq
Mail queue is empty
You have mail in /var/spool/mail/root
[[email protected] ~]# cat /var/spool/mail/root
From [email protected] Sat May 20 03:13:41 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from westos-mail.westos.com (unknown [172.25.254.112])
by qq-mail.westos.com (Postfix) with ESMTP id 3442417E84B
for <[email protected]>; 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: [email protected]
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 [email protected]
Subject: haa
haa
.
EOT
2 mailq
接收邮件端:
过程如下:
发邮件端:
[[email protected] ~]# mail [email protected]
Subject: haa
haa
.
EOT
[[email protected] ~]# mailq
Mail queue is empty
收邮件端:
[[email protected] ~]# vim /etc/aliases
[[email protected] ~]# postalias /etc/aliases ###立即生效###
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# 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 [email protected]
Subject: hello
kaa
.
EOT
2 mailq
收邮件端:
1 mail -u student ###查看student的邮件###
2 mail -u root ###查看root的邮件###
过程如下:
发邮件端:
[[email protected] ~]# mail [email protected]
Subject: hello
kaa
.
EOT
[[email protected] ~]# mailq
Mail queue is empty
[[email protected] ~]# vim /etc/aliases
moreuser: :include:/etc/postfix/moreuser
别名
[[email protected] ~]# vim /etc/postfix/moreuser
student
root
收邮件端:
[[email protected] ~]# postalias /etc/aliases
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# > /var/spool/mail/root
[[email protected] ~]# mail -u student ###查看student的邮件###
No mail for student
[[email protected] ~]# mail -u root ###查看root的邮件###
No mail for root
[[email protected] ~]# 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
[[email protected] ~]# 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:[email protected] ###邮件从[email protected]发送###
250 2.1.0 Ok
rcpt to:[email protected] ###邮件发到[email protected]###
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
过程如下:
[[email protected] ~]# 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
[[email protected] ~]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access" #用smtpd_client_restrictions参数去检测/etc/postfix/access,但真正检测的是加密后的文件access.db####
[[email protected] ~]# vim /etc/postfix/main.cf
[[email protected] ~]# vim /etc/postfix/access
[[email protected] ~]# vim /etc/postfix/access
[[email protected] ~]# postmap /etc/postfix/access ###加密###
[[email protected] ~]# ls
anaconda-ks.cfg Documents Music Public Videos
Desktop Downloads Pictures Templates
[[email protected] ~]# cd /etc/postfix/
[[email protected] postfix]# ls
access generic master.cf virtual
access.db header_checks relocated
canonical main.cf transport
[[email protected] postfix]#
测试:
[[email protected] 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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.
[[email protected] 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###编辑文件###
内容:
[email protected] REJECT###拒绝[email protected]用户发送###
4 postmap /etc/postfix/sender###加密###
5 cd /etc/postfix/###加密后的文件在该目录下
6 systemctl restart postfix.service###重启服务###
过程如下:
[[email protected] ~]# 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
[[email protected] ~]# postconf -e "smtpd_sender_restrictions = check_sender_acess hash:/etc/postfix/sender"
[[email protected] ~]# vim /etc/postfix/sender
[[email protected] ~]# postmap /etc/postfix/sender
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# systemctl start named
[[email protected] ~]# systemctl stop firewalld
[[email protected] postfix]# ls
access canonical header_checks master.cf sender transport
access.db generic main.cf relocated sender.db virtual
测试:
[[email protected] 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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.
[[email protected] Desktop]$
八 限制用户接收
接受邮件端:
1 postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
2 vim /etc/postfix/recip
内容:
[email protected] REJECT###限制[email protected]用户接收###
3 postmap /etc/postfix/recip ###加密###
4 systemctl restart postfix.service
过程如下:
[[email protected] ~]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
[[email protected] ~]# vim /etc/postfix/recip
[email protected] REJECT
[[email protected] ~]# postmap /etc/postfix/recip
[[email protected] ~]# systemctl restart postfix.service
测试:
[[email protected] 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:[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>
hello
hello
.
250 2.0.0 Ok: queued as D00F9EAC27
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: 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
[email protected] [email protected]
真实用户虚拟用户
4 postmap /etc/postfix/generic###加密###
测试:
su - westos
mail [email protected]
过程如下:
邮件发送方:
[[email protected] ~]# 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 =
[[email protected] ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
[[email protected] ~]# vim /etc/postfix/generic
[[email protected] ~]# postmap /etc/postfix/generic
测试:
邮件发送方:
[[email protected] ~]# su - westos
[[email protected] ~]$ mail [email protected]
Subject: hello hello
hello
.
EOT
[[email protected] ~]$ mailq
Mail queue is empty
邮件接收方:
[[email protected] ~]# 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 [email protected] Sat May 20 04:36 15/510
>N 3 [email protected] Sat May 20 22:32 21/725 "hello hello"
& 3
Message 3:
From [email protected] Sat May 20 22:32:21 2017
Return-Path: <[email protected]>###名字发生了变化###
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Sat, 20 May 2017 22:32:23 -0400
To: [email protected]
Subject: hello hello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected]
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
过程如下:
[[email protected] westos]# vim /etc/named.rfc1912.zones
zone "haa.com" IN {
type master;
file "haa.com.zone";
allow-update { none; };
};
[[email protected] named]# cd /var/named/
[[email protected] named]# ls
data named.ca named.localhost qq.com.zone westos.com.zone
dynamic named.empty named.loopback slaves
[[email protected] named]# cp -p qq.com.zone haa.com.zone
[[email protected] 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.
~
[[email protected] named]# systemctl restart named
2)配置
1 postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
2 vim /etc/postfix/virtual
内容:
[email protected] [email protected]
别名真名
3 postmap /etc/postfix/virtual###加密###
4 systemctl restart postfix.service
过程如下:
[[email protected] 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 =
[[email protected] named]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
[[email protected] named]# vim /etc/postfix/virtual
[email protected] [email protected]
别名真名
[[email protected] named]# postmap /etc/postfix/virtual###加密###
[[email protected] named]# systemctl restart postfix.service
测试:
邮件发送端:
1 mail [email protected]###发邮件###
2 mailq
邮件接收端:
过程如下:
[[email protected] 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 [email protected] Sat May 20 22:42:59 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Sat, 20 May 2017 22:42:58 -0400
To: [email protected]
Subject: hai
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
hai
&
[[email protected] ~]# mail [email protected]###发邮件###
Subject: hai
hai
.
EOT
[[email protected] ~]# mailq
Mail queue is empty
[[email protected] ~]#
(二)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
过程如下:
[[email protected] ~]# yum install dovecot -y
[[email protected] ~]# systemctl start dovecot
[[email protected] ~]# 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
[[email protected] ~]# vim /etc/dovecot/dovecot.conf
[[email protected] ~]# vim /etc/dovecot/conf.d/10-mail.conf
[[email protected] ~]# systemctl restart dovecot.service
[[email protected] ~]# mkdir /etc/skel/mail/.imap -p
[[email protected] ~]# touch /etc/skel/mail/.imap/INBOX
[[email protected] ~]# 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.
[[email protected] ~]# mkdir /home/westos/mail/.imap -p
[[email protected] ~]# touch /home/westos/mail/.imap/INBOX
测试:
mutt -f pop://[email protected]
三 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 [email protected] 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 "[email protected]" mysql:/etc/postfix/mailuser.cf ###查看是否会输出用户名,若输出,则说明写对了###
8 postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
9 postmap -q "[email protected]" 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 [email protected]###看能否使用数据库里的用户发送邮件###
过程如下:
[[email protected] myadmin]# cd /etc/postfix/
[[email protected] postfix]# vim mailuser.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = username
where_field = username
[[email protected] postfix]# postmap -q "[email protected]" mysql:mailuser.cf
postmap: fatal: bad string length 0 < 1: mailuser.cf_dbname =
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf
[[email protected] postfix]# vim mailuser.cf
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf
[email protected]
[[email protected] postfix]# cp mailuser.cf maildomain.cf
[[email protected] postfix]# vim maildomain.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
~
[[email protected] postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
lee.com,lee.com
[[email protected] postfix]# cp mailuser.cf mailbox.cf
[[email protected] postfix]# vim mailbox.cf
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
[[email protected] postfix]# postmap -q "[email protected]" 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
[[email protected] postfix]# vim mailbox.cf
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf
/mnt/lee.com/lee
[[email protected] postfix]#
[[email protected] ~]# groupadd -g 666 vmail
[[email protected] ~]# useradd -s /sbin/nologin -u 666 vmail -g 666
[[email protected] ~]# id vmail
uid=666(vmail) gid=666(vmail) groups=666(vmail)
[[email protected] ~]# 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 =
[[email protected] ~]# postconf -e "virtual_mailbox_base = /home/vmail"
[[email protected] ~]# postconf -e "virtual_uid_maps = static:666"
[[email protected] ~]# postconf -e "virtual_gid_maps = static:666"
[[email protected] ~]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
[[email protected] ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfi/maildomain.cf
[[email protected] ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"
[[email protected] ~]# ll /etc/postfix/mailuser.cf
-rw-r--r--. 1 root root 134 May 21 04:06 /etc/postfix/mailuser.cf
[[email protected] ~]# ll /etc/postfix/mailbox.cf
-rw-r--r--. 1 root root 133 May 21 04:21 /etc/postfix/mailbox.cf
[[email protected] ~]# ll /etc/postfix/maildomain.cf
-rw-r--r--. 1 root root 130 May 21 04:19 /etc/postfix/maildomain.cf
[[email protected] ~]# cd /home/vmail/
[[email protected] vmail]# ls
[[email protected] vmail]# mail [email protected]
Subject: hello
hello hello
.
EOT
[[email protected] vmail]# mailq
Mail queue is empty
[[email protected] vmail]# ls
lee.com mail
[[email protected] vmail]# cd lee.com/
[[email protected] lee.com]# ls
lee
[[email protected] lee.com]# cd lee/
[[email protected] lee]# ls
cur new tmp
[[email protected] lee]# cd new/
[[email protected] new]# cat new/
cat: new/: No such file or directory
[[email protected] new]# cd ne
-bash: cd: ne: No such file or directory
[[email protected] new]# cd new/
-bash: cd: new/: No such file or directory
[[email protected] new]#
[[email protected] new]# ls
1495357341.Vfd01I30059aaM65037.westos-mail.westos.com
[[email protected] new]# cat 1495357341.Vfd01I30059aaM65037.westos-mail.westos.com
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
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: [email protected]
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: <[email protected]>
From: [email protected] (root)
hello hello