postfix , dovecot 配置
(一)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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341