主机名 | IP | 服务 |
master | 192.168.30.130 | |
slave | 192.168.30.131 |
软件包介绍
包名 | 介绍 |
postfix-2.6.6-2.2.el6_1.x86_64 | postfix的主程序包,必须安装 |
dovecot.x86_64 1:2.0.9-7.el6 | 用于接收邮件 |
安装
[root@master ~]# yum install -y postfix dovecot
配置文件和日志文件位置
[root@master ~]# ls /etc/postfix/ access generic main.cf relocated virtual canonical header_checks master.cf transport [root@master ~]# ls /var/log/maillog /var/log/maillog
启动postfix服务并查看
[root@master ~]# service postfix start [root@master ~]# netstat -antup | grep 25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1570/master tcp 0 0 ::1:25 :::* LISTEN 1570/master [root@master ~]# ps -ef | grep postfix root 1570 1 0 16:53 ? 00:00:00 /usr/libexec/postfix/master postfix 1579 1570 0 16:53 ? 00:00:00 qmgr -l -t fifo -u postfix 2589 1570 0 18:33 ? 00:00:00 pickup -l -t fifo -u root 2673 1842 0 19:06 pts/0 00:00:00 grep postfix
修改配置文件实现postfix发送邮件
[root@master ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.30.130 master sishen.cn 192.168.30.131 slave [root@master ~]# vim /etc/postfix/main.cf mydomain = sishen.cn mynetworks = 192.168.30.0/24,127.0.0.0/8
重启postfix测试
[root@master ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
配置dovecot实现postfix的发送和接收
[root@master ~]# vim /etc/dovecot/dovecot.conf protocols = imap pop3 lmtp #取消前面的注释 login_trusted_networks = 0.0.0.0 #允许所有网络 login_trusted_networks = 192.168.30.0/24 #允许制定IP,两者选其一 [root@master ~]# vim /etc/dovecot/conf.d/10-mail.conf mail_location = mbox:~/mail:INBOX=/var/mail/%u #取消前面的注释,指定收件箱位置 mbox_write_locks = fcntl #默认开启,无需更改
修改.bash_profile文件
[root@master ~]# vim /etc/skel/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH if [ ! -d ~/mail/.imap/INBOX ]; then mkdir -p ~/mail/.imap/INBOX fi
重启服务
[root@master ~]# service dovecot restart
Stopping Dovecot Imap: [ OK ]
Starting Dovecot Imap: [ OK ]
创建用户测试
[root@master ~]# useradd xueji [root@master ~]# echo "xueji:123456" | chpasswd #以下是三种发送邮件的方式
[xueji@master ~]$ mail -s "【xueji】" xueji@sishen.cn < /etc/hosts #注意这里最好写成xueji@192.168.30.130,因为在实际测试过程中,虽然提示发送邮件成功,但实际上收件箱并没有邮件,可能是因为上述配置文件中写的是IP地址段的问题。(个人感觉) [xueji@master ~]$ echo "aa################bb" | mail -s "sishen" sishen@sishen.cn < /etc/passwd [xueji@master ~]$ mail -s 'test-01' sishen@sishen.cn #直接回车 11111111111111 # 输入正文 222222222222222 3333333333333333 # 这里想要结束必须回车换到新一行行首 EOT #然后Ctrl+d
查看邮件
[xueji@master ~]$ mail Heirloom Mail version 12.4 7/29/08. Type ? for help. "/var/spool/mail/xueji": 2 messages 1 unread 1 Mail Delivery System Thu May 24 04:25 74/2473 "Undelivered Mail Returne" >U 2 Mail Delivery System Thu May 24 04:27 74/2469 "Undelivered Mail Returne" & 2 Message 2: From MAILER-DAEMON Thu May 24 04:27:57 2018 Return-Path: <> X-Original-To: xueji@master.localdomain Delivered-To: xueji@master.localdomain Date: Thu, 24 May 2018 04:27:57 +0800 (CST) From: MAILER-DAEMON@master.localdomain (Mail Delivery System) Subject: Undelivered Mail Returned to Sender To: xueji@master.localdomain Auto-Submitted: auto-replied Content-Type: multipart/report; report-type=delivery-status; boundary="36CAFA06AC.1527107277/master.localdomain" Status: RO Part 1: Content-Description: Notification Content-Type: text/plain; charset=us-ascii This is the mail system at host master.localdomain. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to postmaster. If you do so, please include this problem report. You can delete your own text from the attached returned message. The mail system <root@192.168.30.130>: bad address syntax Part 2: Content-Description: Delivery report Content-Type: message/delivery-status Part 3: Content-Description: Undelivered Message Content-Type: message/rfc822 From xueji@master.localdomain Thu May 24 04:27:57 2018 Return-Path: <xueji@master.localdomain> Date: Thu, 24 May 2018 04:27:57 +0800 To: root@192.168.30.130 Subject: 【xueji】 User-Agent: Heirloom mailx 12.4 7/29/08 Content-Type: text/plain; charset=us-ascii From: xueji@master.localdomain 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.30.130 sishen.cn