郵件

郵件(mail)

 

[root@server-dns ~]# hostnamectl set-hostname mailwestos.westos.com

[root@mailwestos ~]# yum install bind -y ##安裝bind

Loaded plugins: langpacks

Resolving Dependencies

--> Running transaction check

.............................

[root@mailwestos ~]# vim /etc/named.conf

 11 //      listen-on port 53 { 127.0.0.1; };

 12 //      listen-on-v6 port 53 { ::1; };

 13         directory       "/var/named"; ##註釋11,12,17行

 14         dump-file       "/var/named/data/cache_dump.db";

 15         statistics-file "/var/named/data/named_stats.txt";

 16         memstatistics-file "/var/named/data/named_mem_stats.txt";

 17 //      allow-query     { localhost; };

 

32         dnssec-validation no; ##關閉DNS安全認證

[root@mailwestos ~]# vim /etc/named.rfc1912.zones

zone "westos.com" IN {

        type master;

        file "westos.com.zone";

        allow-update { none; };

};

 

[root@mailwestos ~]# systemctl restart named

[root@mailwestos named]# cp -p named.localhost westos.com.zone

[root@mailwestos named]# 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.2

westos.com.     MX 1    172.25.254.2.

[root@mailwestos named]# cp -p westos.com.zone linux.com.zone

[root@mailwestos named]# vim linux.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.2

westos.com.     MX 1    172.25.254.2.

~                                                                              

~                                                                              

~                                                                              

~                                                                              

~                                                                              

:%s/westos/linux/g

 

$TTL 1D

@       IN SOA  dns.linux.com. root.linux.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                        NS      dns.linux.com.

dns                     A       172.25.254.2

linux.com.              MX 1    172.25.254.1.

[root@mailwestos named]# vim /etc/named.rfc1912.zones

zone "linux.com" IN {

        type master;

        file "linux.com.zone";

        allow-update { none; };

};

[root@mailwestos named]# systemctl restart named

[root@mailwestos named]# dig -t mx linux.com

 

; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t mx linux.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26215

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

 

;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 4096

;; QUESTION SECTION:

;linux.com. IN MX

 

;; ANSWER SECTION:

linux.com. 86400 IN MX 1 172.25.254.1.

 

;; AUTHORITY SECTION:

linux.com. 86400 IN NS dns.linux.com.

 

;; ADDITIONAL SECTION:

dns.linux.com. 86400 IN A 172.25.254.2

 

;; Query time: 2 msec

;; SERVER: 127.0.0.1#53(127.0.0.1)

;; WHEN: Thu Dec 08 12:57:12 EST 2016

;; MSG SIZE  rcvd: 100

 

[root@mailwestos named]# vim /etc/resolv.conf

# Generated by NetworkManager

search westos.com

namesever 172.25.254.2

 

 

 

[root@maillinux ~]# vim /etc/postfix/main.cf

75 myhostname = maillinux.linux.com

83 mydomain = linux.com

99 myorigin = $mydomain

113 inet_interfaces = all

114 #inet_interfaces = $myhostname

115 #inet_interfaces = $myhostname, localhost

116 #inet_interfaces = localhost

164 mydestination = $myhostname, $mydomain, localhost

測試

[root@mailwestos named]# mail [email protected]

Subject: ew

d

dq

dq

.

EOT

[root@mailwestos named]# mailq ##查看待寄郵件名單

Mail queue is empty

 

 

[root@maillinux ~]# mail -u root ##查看root用戶的所有郵件

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 1 message 1 new

>N  1 root                  Thu Dec  8 13:02  23/738   "ew"

&

 

postqueue -p ##查看寄存隊列內容

Postsuper -d XXXXXXXXXX  ##刪除發送失敗的郵件

Postconf -d ##查看默認配置

Postconf -n ##查看當前的配置

 

虛擬郵件賬號

[root@mailwestos ~]# vim /etc/aliases ##修改虛擬用戶

# Person who should get root's mail

#root:          marc

admin:          root

 

郵件羣發

[root@mailwestos ~]# vim /etc/aliases

more:           :include:/etc/moreusers ##指定羣發的用戶文件

 

[root@mailwestos ~]# postalias /etc/aliases ##生成加密文件

[root@mailwestos ~]# systemctl restart postfix.service

[root@mailwestos ~]# mail admin

Subject: w3w

wd

dd

 

dqdqw

.

EOT

[root@mailwestos ~]# mailq

Mail queue is empty

 

 

 

[root@mailwestos ~]# vim /etc/postfix/virtual

[email protected]                [email protected]

 

You have new mail in /var/spool/mail/root

[root@mailwestos ~]# ls

anaconda-ks.cfg  Documents  Music     Public     Videos

Desktop          Downloads  Pictures  Templates

 

[root@mailwestos postfix]# postmap virtual

[root@mailwestos postfix]# ls

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport  virtual.db

[root@mailwestos ~]# postconf -d | grep virtual

[root@mailwestos ~]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

[root@mailwestos ~]# systemctl restart postfix.service

[root@mailwestos ~]# mail [email protected]

Subject: haha

dwqd

qwd

qw

.

EOT

[root@mailwestos ~]# mailq

Mail queue is empty

 

發出郵件地址僞裝

[root@mailwestos ~]# vim /etc/postfix/generic

#                                                                     GENERIC(5)

[email protected]                 [email protected]##前面是真實域名,後面是僞裝域名

[root@mailwestos postfix]# postmap generic

[root@mailwestos postfix]# 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@mailwestos postfix]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

[root@mailwestos postfix]# systemctl restart postfix.service

測試

[root@foundation68 ~]# telnet 172.25.254.2 25 ##連接端口爲25

Trying 172.25.254.2...

Connected to 172.25.254.2.

Escape character is '^]'.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello

250-mailwestos.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 ##data之後加郵件內容

354 End data with <CR><LF>.<CR><LF>

dqwd

dwq

dwq

.

250 2.0.0 Ok: queued as 8BE5F26AB5B

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

[root@mailwestos postfix]# mail -u root

No mail for root

[root@mailwestos postfix]# mail -u root

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 1 message 1 new

>N  1 [email protected]        Fri Dec  9 00:19  12/323   

& 1

Message  1:

From [email protected]  Fri Dec  9 00:19:07 2016

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Status: R

 

dqwd

dwq

dwq

 

[root@mailwestos postfix]# vim access

#        Yorktown Heights, NY 10598, USA

172.25.254.68   REJECT

[root@mailwestos postfix]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"

[root@mailwestos postfix]# systemctl restart postfix.service

測試

[root@foundation68 ~]# telnet 172.25.254.2 25

Trying 172.25.254.2...

Connected to 172.25.254.2.

Escape character is '^]'.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello

250-mailwestos.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]

451 4.3.5 <unknown[172.25.254.68]>: Client host rejected: Server configuration error

 

[root@mailwestos postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"   ##將該命令加到主配置文件

[root@mailwestos postfix]# systemctl restart postfix.service

測試

[root@foundation68 ~]# telnet 172.25.254.2 25

Trying 172.25.254.2...

Connected to 172.25.254.2.

Escape character is '^]'.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello

250-mailwestos.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]

451 4.3.5 <[email protected]>: Sender address rejected: Server configuration error

##發送方的地址被拒絕

 

[root@mailwestos postfix]# vim recip  ###recip可自己設置文件名

[root@mailwestos postfix]# postmap recip

[root@mailwestos postfix]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

[root@mailwestos postfix]# vim /etc/postfix/main.cf

[root@mailwestos postfix]# systemctl restart postfix.service

測試

[root@foundation68 ~]# telnet 172.25.254.2 25

Trying 172.25.254.2...

Connected to 172.25.254.2.

Escape character is '^]'.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello

250-mailwestos.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]

554 5.7.1 <[email protected]>: Recipient address rejected: Access denied

##收件人拒絕接收

 

[root@mailwestos postfix]# vim /etc/postfix/main.cf

sample_directory = /usr/share/doc/postfix-2.10.1/samples

 

# readme_directory: The location of the Postfix README files.

#

readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

virtual_alias_maps = hash:/etc/postfix/virtual

smtp_generic_maps = hash:/etc/postfix/generic

#smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

#smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip

"/etc/postfix/main.cf" 684L, 27488C                           683,1         Bot

 

 

[root@mailwestos postfix]# yum install dovecot -y

Loaded plugins: langpacks

Package 1:dovecot-2.2.10-4.el7.x86_64 already installed and latest version

Nothing to do

[root@mailwestos postfix]# systemctl start dovecot

[root@mailwestos postfix]# vim /etc/dovecot/dovecot.conf

 24 protocols = imap pop3 lmtp

 48 login_trusted_networks = 0.0.0.0/0

 49 disable_plaintext_auth = no

 

[root@mailwestos postfix]# cd /etc/dovecot/conf.d/

[root@mailwestos conf.d]# vim 10-mail.conf

30 mail_location = mbox:~/mail:INBOX=/var/mail/%u

[root@mailwestos conf.d]# systemctl restart dovecot.service

 

[root@maillinux ~]# yum install mutt -y

Loaded plugins: langpacks

Package 5:mutt-1.5.21-26.el7.x86_64 already installed and latest version

Nothing to do

[root@maillinux ~]# mutt -f imap://[email protected]

wKioL1hKlW_TGucPAAdr5cn4wN0561.png-wh_50

 

安裝雷鳥

[root@foundation68 mnt]# ls

rhel-server-7.0-x86_64-dvd.iso  thunderbird-31.2.0-1.el7.x86_64.rpm

[root@foundation68 mnt]# rpm -ivh  thunderbird-31.2.0-1.el7.x86_64.rpm

warning: thunderbird-31.2.0-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:thunderbird-31.2.0-1.el7         ################################# [100%]

 

[root@mailwestos named]# 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.2

westos.com.             MX 1    172.25.254.1.

[root@mailwestos named]# vim /etc/postfix/main.cf

mynetworks = 172.25.254.1

 

 

[root@mailwestos named]# systemctl restart postfix.service

 

[root@maillinux ~]# vim /etc/postfix/main.cf

 99 myorigin = westos.org

140 local_transport = error:local delevery disabled

164 mydestination =

313 relayhost = 172.25.254.2

 

[root@maillinux ~]# systemctl restart postfix.service

測試

[root@maillinux ~]# mail [email protected]

Subject: w3w

dqwd

dqw

d

.

EOT

[root@maillinux ~]# mailq

Mail queue is empty

 

[root@mailwestos named]# mail -u root

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 2 messages 1 new

    1 root                  Fri Dec  9 02:31  24/751   "www"

>N  2 root                  Fri Dec  9 02:36  23/740   "w3w"

& 2

Message  2:

From [email protected]  Fri Dec  9 02:36:32 2016

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Fri, 09 Dec 2016 02:36:34 -0500

To: [email protected]

Subject: w3w

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: [email protected] (root)

Status: R

 

dqwd

dqw

d

 

[root@mailwestos named]# systemctl start mariadb

[root@mailwestos named]# systemctl start httpd

[root@mailwestos postfix]# mysql -uroot -phello

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 55

..

MariaDB [(none)]> create USER postfix@localhost identified by 'postfix';

Query OK, 0 rows affected (0.00 sec)

[root@mailwestos postfix]# mysql -upostfix -ppostfix

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 56

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| westos             |

+--------------------+

MariaDB [westos]> select * from vuser;

+----------------+----------+------------+-----------------------------+

| usename        | password | domain     | maidir                      |

+----------------+----------+------------+-----------------------------+

| [email protected]  | yz       | redhat.com | /home/vmail/redhat.com/yz/  |

| [email protected] | lee      | westos.com | /home/vmail/westos.com/lee/ |

+----------------+----------+------------+-----------------------------+

[root@mailwestos postfix]# cat mysql-user.cf

host = localhost

user = postfix

password = postfix

dbname = westos

table = vuser

select_field = username

where_field = username

[root@mailwestos postfix]# cat mysql-domain.cf

host = localhost

user = postfix

password = postfix

dbname = westos

table = vuser

select_field = domain

where_field = domain

[root@mailwestos postfix]# cat mysql-mailbox.cf

host = localhost

user = postfix

password = postfix

dbname = westos

table = vuser

select_field = maidir

where_field = username

 

[root@mailwestos postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf

[email protected]

[root@mailwestos postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-domain.cf

redhat.com

[root@mailwestos postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf

/home/vmail/redhat.com/yz/

 

[root@mailwestos ~]# groupadd -g 666 vmail

[root@mailwestos ~]# useradd -u 666 -g 666 vmail

[root@mailwestos ~]# cd /home/

[root@mailwestos home]# ls

student  vmail

[root@mailwestos home]# postconf -d | grep virtual

[root@mailwestos home]# postconf -e "virtual_mailbox_base = /home/vmail"

[root@mailwestos home]# postconf -e "virtual_uid_maps = static:666"

[root@mailwestos home]# postconf -e "virtual_gid_maps = static:666"

[root@mailwestos home]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"

[root@mailwestos home]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"

[root@mailwestos home]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"

 

[root@mailwestos conf.d]# vim 10-auth.conf

123 !include auth-sql.conf.ext

[root@mailwestos conf.d]# vim 10-mail.conf

30 mail_location = maildir:/home/vmail/%d/%n

168 first_valid_uid = 666

175 first_valid_gid = 666

 

[root@mailwestos doc]# cd dovecot-2.2.10/

[root@mailwestos dovecot-2.2.10]# cd example-config/

[root@mailwestos example-config]# cp -p dovecot-sql.conf.ext /etc/dovecot/

[root@mailwestos example-config]# cd /etc/dovecot/

[root@mailwestos dovecot]# ls

conf.d  dovecot.conf  dovecot-sql.conf.ext

[root@mailwestos dovecot]# vim dovecot-sql.conf.ext

 

 32 driver = mysql

 71 connect = host=localhost db=westos user=postfix password=postfix

 78 default_pass_scheme = PLAIN

107 password_query = \

108   SELECT username, domain, password \

109   FROM users WHERE username = '%u' AND domain = '%d'

127 user_query = SELECT maildir 666 AS uid, 666 AS gid FROM muser WHERE usename= '%u'

[root@mailwestos dovecot]# systemctl restart dovecot.service

測試

[root@maillinux ~]# telnet 172.25.254.2 110

Trying 172.25.254.2...

Connected to 172.25.254.2.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user [email protected]

+OK

pass yz

+OK Logged in.

quit

+OK Logging in.

Connection closed by foreign host.

wKiom1hKlWyQm0IqAAQXoDDZDjI072.png-wh_50



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章