NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

1.首先配置兩臺虛擬機器,

名字改為mailwestos.westos.com和maillinux.linux.com

ip分別設定為172.25.254.119和172.25.254.219

yum 源配置好。

2.配置dns

在mailwestos主機上:yum install bind -y

[[email protected] ~]# vim /etc/named.conf

//      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; };

 

[email protected] ~]# cd /var/named

[[email protected] named]# ls

data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves

[[email protected] named]# vim /etc/named.rfc1912.zones

zone “westos.com” IN {

        type master;

        file “westos.com.zone”;

        allow-update { none; };

};

 

zone “linux.com” IN {

        type master;

        file “linux.com.zone”;

        allow-update { none; };

};

[[email protected] named]# cp -p named.localhost westos.com.zone

[[email protected] 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.119

westos.com.     MX 1    172.25.254.119.

                              

[[email protected] named]# cp -p westos.com.zone linux.com.zone //注意 -p

[[email protected] named]# vim linux.com.zone

$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.119

linux.com.      MX 1    172.25.254.219.

~                                             

[[email protected] named]# systemctl restart named

[[email protected] named]# vim /etc/resolv.conf

nameserver 172.25.254.119

[[email protected] named]# dig -t mx westos.com

2.傳送郵件

直接mail [email protected]時,會顯示無法傳送,linux(172.25.254.219)的25 埠沒有開啟

[[email protected] named]# netstat -antlpe | grep 25 //檢視25埠是否開啟

[[email protected] named]# rpm -qa | grep postfix //檢視郵件服務協議是否安裝

 

[[email protected] named]# vim /etc/postfix/main.cf

 76 myhostname = mailwestos.westos.com

83 mydomain = westos.com

99 myorigin = $mydomain

113 inet_interfaces = all

116 #inet_in164 mydestination = $myhostname, $mydomain, localhost

terfaces = localhost

164 mydestination = $myhostname, $mydomain, localhost

:wq

 

[[email protected] named]# systemctl restart postfix.service

[[email protected] named]# systemctl stop firewalld.service

 

在linux(219)主機上做同樣的配置改動

[[email protected] named]# systemctl stop firewalld.service

 

[[email protected] ~]# mail [email protected]inux.com

Subject: test

test

ddd

.

EOT

可以傳送成功!

 

mail //檢視接受的郵件

mailq //檢視郵件是否發出

postqueue -f //郵件佇列重新整理

> /var/spool/mail/root //清空郵件佇列

 

3.空殼郵件客戶端

[[email protected] ~]# vim /etc/aliases

在最後新增:admin:          root

 

[[email protected] ~]# postmap /etc/aliases

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]#postsuper -d 郵件編號(50CBD3260) //刪除郵件

 

[[email protected] ~]#mail [email protected]

編輯郵件

 

[[email protected] ~]#mail

在linux主機檢視郵件時可以發現實際上時發給了root使用者

 

4.群發郵件

[[email protected] ~]# vim /etc/aliases

新增:more:           :include:/etc/postfix/users

[[email protected] ~]# vim /etc/postfix/users

root

student

[[email protected] ~]# postalias /etc/aliases

[[email protected] ~]# systemctl restart postfix.service

 

[[email protected] ~]# mail [email protected]

 

[[email protected] ~]# mail

[[email protected] ~]# mail -u student

 

5.企業級郵箱(虛擬郵箱)

(1)

[[email protected] ~]# vim /etc/postfix/virtual

新增:[email protected] [email protected]

[[email protected] ~]# postmap /etc/postfix/virtual

[[email protected] ~]# ls /etc/postfix/

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport  virtual.db

[[email protected] ~]# postconf -d | grep virtual

[[email protected] ~]# postconf -e “virtual_alias_maps = hash:/etc/postfix/virtual”

[[email protected] ~]# mail [email protected]

 

[[email protected] ~]# mail

可以在westos主機上檢視到實際上發給了[email protected]

 

[[email protected] ~]# vim /etc/postfix/virtual

新增:@qq.com                 @linux.com    //虛擬的在前面,真實的在後面

[[email protected] ~]# postmap /etc/postfix/virtual

[[email protected] ~]# postconf -d | grep virtual //為了找到virtual_alias_maps =

[[email protected] ~]# postconf -e “virtual_alias_maps = hash:/etc/postfix/virtual”

[[email protected] ~]# mail [email protected] //任意使用者

(2)

自己主機可以接受虛擬域名的郵件:

[[email protected] ~]# mail -u student

 Message  1:

From [email protected]  Fri Mar 10 22:42:45 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

//可以看到實際上是發給了[email protected]

 

(3)

其他主機給虛擬域名(qq.com)傳送郵件本來是不能傳送的,配置以下服務就可以給他及虛擬域名傳送郵件

[[email protected] ~]# mail [email protected]

[[email protected] ~]# mailq

-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-

4F8AD17E863      452 Sat Mar 11 00:43:26  [email protected]

(Host or domain name not found. Name service error for name=qq.com type=MX: Host not found, try again)

                                         [email protected]

 

— 0 Kbytes in 1 Request.

[[email protected] ~]# vim /etc/named.rfc1912.zones

新增:

zone “qq.com” IN {

        type master;

        file “qq.com.zone”;

        allow-update { none; };

};

[[email protected] named]# cd /var/named

[[email protected] named]# ls

data     linux.com.zone  named.empty      named.loopback  westos.com.zone

dynamic  named.ca        named.localhost  slaves

[[email protected] named]# cp -p linux.com.zone qq.com.zone

[[email protected] named]# vim qq.com.zone

$TTL 1D

@       IN SOA  qq.com. root.qq.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.qq.com.

dns             A       172.25.254.119

qq.com.         MX 1    172.25.254.219.

~                                        

[[email protected] named]# systemctl restart named

[[email protected] named]# postqueue -f

[[email protected] named]# mailq

[[email protected] named]# systemctl restart postfix.service

配置之後就可以傳送過去,完全實現了企業級郵箱,建立了虛擬郵箱

 

(4)

實現以以虛擬域名為傳送域名傳送郵件,即就是在接受端看見傳送者時虛擬域名:

 

[email protected] ~]# postmap /etc/postfix/generic

在最後新增:@linux.com              @qq.com //真實的寫在前面,虛擬的解除安裝後面

 postmap /etc/postfix/generic

[[email protected] ~]# postconf -d| grep generic //為了找到smtp_generic_maps =

[[email protected] ~]# postconf -e “smtp_generic_maps = hash:/etc/postfix/generic”

[[email protected] ~]# systemctl restart postfix.service

效果:

[[email protected] ~]# mail [email protected]

Subject: hhhhhhhhhhhhhhhhhh

hhhhhhhhhhhhhh

.

EOT

 

 

[[email protected] named]# mail

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

“/var/spool/mail/root”: 11 messages 4 unread

    1 root                  Fri Mar 10 21:43  23/752   “test”

    2 root                  Fri Mar 10 21:57  24/782   

    3 Mail Delivery System  Fri Mar 10 22:17  77/2509  “Undelivered Mail Retu”

    4 root                  Fri Mar 10 22:21  19/582   “oooooo”

    5 root                  Fri Mar 10 22:22  22/768   “pppppppppppp”

>U  6 root                  Fri Mar 10 22:25  19/574   “kkkkkkk”

    7 root                  Fri Mar 10 22:27  26/903   “hhhhhhhh”

 U  8 root                  Sat Mar 11 00:55  23/752   “jhkfahd”

 U  9 root                  Sat Mar 11 00:57  21/732   

   10 root                  Sat Mar 11 01:00  23/743   “adsf”

 U 11 root                  Sat Mar 11 01:01  22/761   “hhhhhhhhhhhhhhhhhh”

& 11

Message 11:

From [email protected]  Sat Mar 11 01:01:51 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 11 Mar 2017 01:01:51 -0500

To: [email protected]

Subject: hhhhhhhhhhhhhhhhhh

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

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

From: [email protected] (root)

Status: RO

 

hhhhhhhhhhhhhh

 

& q

New mail has arrived.

Held 11 messages in /var/spool/mail/root

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

 

6.在另一臺主機上實現遠端傳送郵件和遠端登陸郵件

在60主機上:

[[email protected] Desktop]# yum install telnet

[[email protected] Desktop]# systemctl start telnet

[[email protected] Desktop]# telnet 172.25.254.119 25

Trying 172.25.254.119…

Connected to 172.25.254.119.

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

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

jijijijiji

jijijiji

jiiji

.

250 2.0.0 Ok: queued as A4C3B17E859

q

502 5.5.2 Error: command not recognized

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

[[email protected] ~]# mail

可以在客戶端主機上檢視到郵件 /

但是在遠端主機未配置接受郵件的服務,還不能在遠端主機上接受郵件,客戶端配置如下配置如下:

 

7.遠端接受郵件;

在客戶端:

[[email protected] ~]# yum install dovecot

[[email protected] ~]# systemctl start dovecot

[[email protected] ~]# netstat -antlpe | grep dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      0          207079     1486/dovecot        

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      0          207055     1486/dovecot        

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      0          207053     1486/dovecot        

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      0          207077     1486/dovecot        

tcp6       0      0 :::993                  :::*                    LISTEN      0          207080     1486/dovecot        

tcp6       0      0 :::995                  :::*                    LISTEN      0          207056     1486/dovecot        

tcp6       0      0 :::110                  :::*                    LISTEN      0          207054     1486/dovecot        

tcp6       0      0 :::143                  :::*                    LISTEN      0          207078     1486/dovecot

        

[[email protected] ~]# vim /etc/dovecot/dovecot.conf

 

24 protocols = imap pop3 lmtp

48 login_trusted_networks = 0.0.0.0

49 disable_plaintext_auth = no

 

 

[[email protected] ~]# cd /etc/dovecot/conf.d/

[[email protected] conf.d]# ls

10-auth.conf       90-plugin.conf

10-director.conf   90-quota.conf

10-logging.conf    auth-checkpassword.conf.ext

10-mail.conf       auth-deny.conf.ext

10-master.conf     auth-dict.conf.ext

10-ssl.conf        auth-ldap.conf.ext

15-lda.conf        auth-master.conf.ext

15-mailboxes.conf  auth-passwdfile.conf.ext

20-imap.conf       auth-sql.conf.ext

20-lmtp.conf       auth-static.conf.ext

20-pop3.conf       auth-system.conf.ext

90-acl.conf        auth-vpopmail.conf.ext

[[email protected] conf.d]# vim 10-mail.conf

 

[[email protected] conf.d]# systemctl restart dovecot.service

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

 

[[email protected] conf.d]# su – student

[[email protected] ~]$ mkdir mail

[[email protected] ~]$ ls

mail

[[email protected] ~]$ cd mail

[[email protected] mail]$ mkdir /home/student/mail/.imap

[[email protected] mail]$ touch /home/student/mail/.imap/INBOX

 

在遠端主機端:

[[email protected] Desktop]# yum install mutt -y

[[email protected] Desktop]# systemctl start mutt

[[email protected] Desktop]# mutt -f pop://[email protected]

遠端登陸就可以檢視到客戶端主機上的郵件

 

8.配置開機就可以自動建立:/home/student/mail/.imap/INBOX

 

[[email protected] ~]# cd /etc/skel

[[email protected] skel]# ls

[[email protected] skel]# mkdir mail

[[email protected] skel]# cd mail

[[email protected] mail]# mkdir .imap

[[email protected] mail]# touch .imap/INBOX

[[email protected] mail]# ll -l /etc/skel/mail/.imap/INBOX

-rw-r–r–. 1 root root 0 Mar 11 01:57 /etc/skel/mail/.imap/INBOX

[[email protected] mail]# useradd test

[[email protected] mail]# passwd test

Changing password for user test.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[[email protected] mail]# su – test

[[email protected] ~]$ ls

mail

 

9.posrfix客戶端接受郵件 mysql的相關配置 php:

 

 

[[email protected] ~]$ yum install mariadb-server httpd php php-mysql

[[email protected] test]# systemctl start mariadb

[[email protected] test]# vim /etc/my.cnf

 

# instructions in http://fedoraproject.org/wiki/Systemd

skip-networking=1

[mysqld_safe]

 

[[email protected] test]# mysql_secure_installation

設定mysql客戶端root使用者登陸的密碼

[[email protected] test]# systemctl restart mariadb.service

 

[email protected] test]# cd /var/www/html/

lftp 172.25.254.250:/pub/docs/software> get phpMyAdmin-3.4.0-all-languages.tar.bz2

4548030 bytes transferred  

[[email protected] html]# tar jxf  phpMyAdmin-3.4.0-all-languages.tar.bz2

[[email protected] html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin

[[email protected] html]# cd mysqladmin/

[[email protected] mysqladmin]# ls

[[email protected] mysqladmin]# cp config.sample.inc.php config.inc.php

[[email protected] mysqladmin]# vim config.inc.php

 

17 $cfg[‘blowfish_secret’] = ‘westos’; /* YOU MUST     FILL IN THIS FOR COOKIE AUTH! */

 

[[email protected] mysqladmin]# systemctl restart httpd

 

[[email protected] mysqladmin]# mysql -uroot -p

MariaDB [(none)]> CREATE USER [email protected] identified by ‘postfix’;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT INSERT.SELECT on email.* to [email protected];

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘INSERT.SELECT on email.* to [email protected]’ at line 1

MariaDB [(none)]> GRANT INSERT,SELECT on email.* to [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit

 

[[email protected] mysqladmin]# mysql -upostfix -ppostfix

 

[[email protected] mysqladmin]# cd /etc/postfix

[[email protected] postfix]# ls

access     generic        main.cf    relocated  users

canonical  header_checks  master.cf  transport  virtual

[[email protected] postfix]# vim mysql-user.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = username

where_field = username

~                    

[[email protected] postfix]# cp mysql-user.cf mysql-domain.cf  

[[email protected] postfix]#vim mysql-domail.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = domain

where_field = domain

~                                                

[[email protected] postfix]# cp mysql-user.cf mysql-mailbox.cf

[[email protected] postfix]# vim mysql-mailbox.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = maildir

where_field = username

~                    

[[email protected] postfix]# postmap -q “redhat.com” mysql:/etc/postfix/mysql-domain.cf

redhat.com

[[email protected] postfix]# postmap -q “[email protected]” mysql:/etc/postfix/mysql-mailbox.cf

/var/spool/redhat.com/admin

[[email protected] postfix]#  postmap -q “[email protected]” mysql:/etc/postfix/mysql-user.cf

[email protected]

 

[[email protected] postfix]# groupadd -g 888 vmail

[[email protected] postfix]# useradd -u 888 -g 888 vmail

[[email protected] postfix]# cd /home/vmail/

[[email protected] vmail]# postconf -d | grep virtual

[[email protected] vmail]# postconf -e “virtual_mailbox_base = /home/vmail”

[[email protected] vmail]# postconf -e “virtual_gid_maps = static:888”

[[email protected] vmail]# postconf -e “virtual_uid_maps = static:888”

[[email protected] vmail]# postconf -e “virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf”

[[email protected] vmail]# postconf -e “virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf”

[[email protected] vmail]# postconf -e “virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf”

[[email protected] vmail]# vim /etc/postfix/main.cf

 

679 readme_directory = /usr/share/doc/postfix-2.10.    1/README_FILES

680 virtual_gid_maps = static:666

681 virtual_uid_maps = static:666

682 virtual_alias_maps = mysql:/etc/postfix/mysql-u    ser.cf

683 virtual_mailbox_domains = mysql:/etc/postfix/my    sql-domain.cf

684 virtual_mailbox_maps = mysql:/etc/postfix/mysql    -mailbox.cf

685 virtual_mailbox_base = /home/vmail

 

[[email protected] ~]# cd /home/vmail

[[email protected] vmail]# mail [email protected]

Subject: jjjjjjjjjjjjjjjjj

dddddddddddd

ccccccccc

.

EOT

[[email protected] vmail]# mailq

Mail queue is empty

[[email protected] vmail]# cd /home/

[[email protected] home]# ls

student  vmail

[[email protected] home]# cd vmail/

[[email protected] vmail]# ls

redhat.com

[[email protected] vmail]# cd redhat.com/

[[email protected] redhat.com]# ls

admiin  admin

[[email protected] redhat.com]# rm -fr admiin/

[[email protected] redhat.com]# cd a

-bash: cd: a: No such file or directory

[[email protected] redhat.com]# cd admin/

[[email protected] admin]# ls

cur  new  tmp

[[email protected] admin]# cd new/

[[email protected] new]# ls

1489737773.Vfd01I136fc76M994432.mailwestos.westos.com

[[email protected] new]# cat 1489737773.Vfd01I136fc76M994432.mailwestos.westos.com

可以檢視到傳到mysql資料庫中的郵件內容

 

 

10.thundebird的使用以及檢視資料庫收件箱:

 

[[email protected] ~]#systemctl stop firewalld.service

[[email protected] ~]#systemctl restart httpd

[[email protected] ~]#systemctl start mariadb

 

[[email protected] ~]# yum list dovecot

[[email protected] ~]#vim /etc/dovecot/dovecot.conf

 48 login_trusted_networks = 0.0.0.0/0 //允許訪問網路地址

 49 disable_plaintext_auth = no //開始明文認證

 

[[email protected] vmail]# vim /etc/dovecot/conf.d/10-auth.conf

123 !include auth-sql.conf.ext

 

[[email protected] vmail]# ll /etc/dovecot/dovecot-sql.conf.ext

ls: cannot access /etc/dovecot/dovecot-sql.conf.ext: No such file or directory

[[email protected] vmail]# cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext

 

[[email protected] ~]# vim /etc/dovecot/dovecot-sql.conf.ext

 32 driver = mysql

71 connect = host=localhost dbname=email user=postfix password=postfix

78 default_pass_scheme = PLAIN

107 password_query = \

108   SELECT username, domain, password \

109   FROM mailusers WHERE username = ‘%u’ AND domain = ‘%d’

125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM mailusers WHERE use    rname = ‘%u’

 

[[email protected] ~]# vim /etc/dovecot//conf.d/10-mail.conf

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

 

在另一主機:

 

[[email protected] Desktop]# telnet 172.25.254.119 110

Trying 172.25.254.119…

Connected to 172.25.254.119.

Escape character is ‘^]’.

OK [XCLIENT] Dovecot ready.

user [email protected]

OK

pass 234

OK Logged in.

quit

同時在主機安裝thunderbird並啟動

驗證成功後可以在thunderbird的收件箱上檢視到postfix上的郵

相關文章

程式語言 最新文章