mail

###########mail服务################

 

服务端主机名为mailwestos.com    ip为172.25.254.22

客户端主机名为maillinux.com     ip为172.25.254.122

 

*******DNS中添加mail*************

 

[root@mailwestos ~]# vim /etc/named.conf               ##配置DNS主配置文件

  11 //      listen-on port 53 { 127.0.0.1; };          ##这三行前面//是将对应配置改为所有

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

  17 //      allow-query     { localhost; };

  32         dnssec-validation no;

 

[root@mailwestos ~]# vim /etc/named.rfc1912.zones      ##添加westos.com及linux.com的正向解析

  25 zone "westos.com" IN {

  26         type master;

  27         file "westos.com.zone";

  28         allow-update { none; };

  29 };

  30

  31 zone "linux.com" IN {

  32         type master;

  33         file "linux.com.zone";

  34         allow-update { none; };

  35 };

 

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

[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.22

  westos.com.     MX 1    172.25.254.22.

[root@mailwestos 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.22

 linux.com.      MX 1    172.25.254.122.                      

[root@mailwestos named]# systemctl restart named       ##重启服务

 

测试:

<服务端>

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

 

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

 

<客户端>

[root@maillinux ~]# vim /etc/resolv.conf

   nameserver 172.25.254.22

[root@maillinux ~]# dig -t mx westos.com

 

[root@maillinux ~]# dig -t mx linux.com

 

*********发送邮件*************

 

若邮件未正常发送,邮件日志位于/var/log/maillog中

mailq命令查看邮件是否正常发送,若未发送,会显示

修改错误后,用postqueue -f命令刷新mailq中未发送邮件,清空mailq中用postsuper -d

 

服务端、客户端该文件配置相似

[root@mailwestos named]# vim /etc/postfix/main.cf             ##配置邮件传输文件

   76 myhostname = mailwestos.westos.com

   83 mydomain = westos.com                                   ##域名

   99 myorigin = $mydomain                                    ##邮件地址后缀

   113 inet_interfaces = all

   116 #inet_interfaces = localhost

   164 mydestination = $myhostname, $mydomain, localhost       ##postfix接收邮件时可接收的域名

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

 

测试:

[root@mailwestos named]# mail [email protected]              ##给本机发邮件

   Subject: kfjdls

   dghk

   .

   EOT

[root@mailwestos named]# mailq                             ##查看邮件是否发出

   Mail queue is empty

[root@mailwestos named]# mail

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

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

       1 root                  Tue Mar 14 04:15  19/567   "test"

   >N  2 root                  Tue Mar 14 05:11  18/559   "kfjdls"

   &

 

[root@mailwestos named]# mail [email protected]             ##给其他主机发邮件

   Subject: test

   test

   .

   EOT

[root@mailwestos named]# mailq

   Mail queue is empty

 

[root@maillinux ~]# mail                                   ##查看是否受到邮件

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

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

   >N  1 root                  Tue Mar 14 05:13  21/738   "test"

   &

 

 

********群发邮件*************

 

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

   admin:          root ##发给admin的邮件实质发给root

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

   Subject: fhdk

   fjdksg

   .

   EOT

[root@maillinux ~]# mail

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

   "/var/spool/mail/root": 2 messages 2 unread

   >U  1 root                  Tue Mar 14 05:13  22/748   "test"

    U  2 root                  Tue Mar 14 05:36  22/754   "fhdk"

   & 2

   Message  2:

   From [email protected]  Tue Mar 14 05:36:16 2017

   Return-Path:

   X-Original-To: [email protected]

   Delivered-To: [email protected]

   Date: Tue, 14 Mar 2017 05:36:16 -0400

   To: [email protected]

   Subject: fhdk

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

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

   From: [email protected] (root)

   Status: RO

 

   fjdksg

 

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

   more:           :include:/etc/postfix/users            ##可以直接发给/etc/postfix/users目录中的用户

[root@maillinux ~]# vim /etc/postfix/users

                    root

                    student

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

   Subject: student

   kkk

   kk

   .

   EOT

[root@maillinux ~]# mail -u student

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

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

   >N  1 root                  Tue Mar 14 05:35  22/755   "student"

   & 1

   Message  1:

   From [email protected]  Tue Mar 14 05:35:18 2017

   Return-Path:

   X-Original-To: [email protected]

   Delivered-To: [email protected]

   Date: Tue, 14 Mar 2017 05:35:17 -0400

   To: [email protected]

   Subject: student

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

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

   From: [email protected] (root)

   Status: R

 

   kkk

   kk

 

   & q

 

********更改收件地址************

 

[root@maillinux ~]# vim /etc/postfix/virtual ##更改收件地址的文件

   [email protected]            [email protected]

   @qq.com                 @linux.com

[root@maillinux ~]# postmap /etc/postfix/virtual

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

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

   Subject: hhhh

   jkjk

   .

   EOT

[root@maillinux ~]# mailq

   Mail queue is empty

[root@maillinux ~]# mail -u student

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

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

       1 root                  Tue Mar 14 05:35  23/766   "student"

   >N  2 root                  Tue Mar 14 06:07  18/550   "hhhh"

   & 2

   Message  2:

   From [email protected]  Tue Mar 14 06:07:40 2017

   Return-Path:

   X-Original-To: [email protected]

   Delivered-To: [email protected]

   Date: Tue, 14 Mar 2017 06:07:39 -0400

   To: [email protected]

   Subject: hhhh

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

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

   From: [email protected] (root)

   Status: R

 

   jkjk

 

   & q

   Held 2 messages in /var/mail/student

 

 

*********更改发件地址**************

 

[root@maillinux ~]# vim /etc/postfix/generic                 ##更改发件地址

[email protected]          [email protected] ##将[email protected]发件改为[email protected]发出

[root@maillinux ~]# postmap /etc/postfix/generic

[root@maillinux ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

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

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

   Subject: iii

   ii

   .

   EOT

[root@mailwestos named]# mail

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

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

   >N  1 root                  Tue Mar 14 06:24  21/724   "iii"

   & 1

   Message  1:

   From [email protected]  Tue Mar 14 06:24:49 2017

   Return-Path:

   X-Original-To: [email protected]

   Delivered-To: [email protected]

   Date: Tue, 14 Mar 2017 06:24:49 -0400

   To: [email protected]

   Subject: iii

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

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

   From: [email protected] (root)                    ##从[email protected]中发出

   Status: R

 

   ii

 

   & q

   Held 1 message in /var/spool/mail/root

 

 

 

**********dovecot加密通信*********************

 

[root@foundation99 Desktop]# telnet 172.25.254.122 25         ##telnet同其他邮件服务器传递邮件

   Trying 172.25.254.122...

   Connected to 172.25.254.122.

   Escape character is '^]'.

   220 maillinux.linux.com ESMTP Postfix

   ehlo hello           ##ehlo同邮件服务器建立初步联系

   250-maillinux.linux.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 .

   kkk

   afd

   fdsg

   .

   250 2.0.0 Ok: queued as 6C7E817E861

   quit

   221 2.0.0 Bye

   Connection closed by foreign host.

[root@mailwestos named]# mail ##查看

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

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

       1 root                  Tue Mar 14 06:24  22/735   "iii"

   >N  2 [email protected]           Tue Mar 14 06:47  15/501   

   & 2

   Message  2:

   From [email protected]  Tue Mar 14 06:47:48 2017

   Return-Path:

   X-Original-To: [email protected]

   Delivered-To: [email protected]

   Status: R

 

   kkk

   afd

   fdsg

 

   & q

 

******配置dovecot、测试**********

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

[root@maillinux ~]# vim /etc/dovecot/dovecot.conf ##dovecot配置文件

   24 protocols = imap pop3 lmtp ##接收邮件协议

   48 login_trusted_networks = 0.0.0.0/0 ##指定所在的网络地址

   49 disable_plaintext_auth = no

[root@maillinux student]# vim /etc/dovecot/conf.d/10-mail.conf

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

[root@maillinux student]#  mkdir /home/student/mail/.imap

[root@maillinux student]# touch /home/student/mail/.imap/INBOX

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

 

测试

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

 mail_第1张图片

 mail_第2张图片

  ***自动建立用户的mail目录

[root@maillinux student]# cd /etc/skel ##框架目录,其中的内容将会在新建用户时自动建立

[root@maillinux skel]# ls

[root@maillinux skel]# mkdir mail

[root@maillinux skel]# mkdir ./mail/.imap

[root@maillinux skel]# touch ./mail/.imap/INBOX

[root@maillinux skel]# useradd test ##新建用户

[root@maillinux skel]# 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.

[root@maillinux skel]# su - test

[test@maillinux ~]$ ls ##有在skel中建立的mail目录

   mail

 

 

你可能感兴趣的:(mail)