RHEL6 postfix+dovecot 邮件服务配置

环境:RHEL6.6

软件:postfix-3.0.0  bind-9.8.2-0.30 mysql-5.5.42  dovecot-2.0.9-7

软件源:本地源,epel源,remi源

邮件服务器IP:192.168.1.110

主机名为mail.mingxiao.info

客户端   IP 192.168.1.77  WinXP,Outlook Express收发邮件

请确保selinux处于permissive状态,防火墙处于关闭状态。

添加几个测试用户,为了测试方便,密码和用户名相同

[[email protected] ~]# useradd jianpan

[[email protected] ~]# passwd jianpan

[[email protected] ~]# useradd shubiao

[[email protected] ~]# passwd shubiao

步骤1:配置DNS

[[email protected] ~]# yum install bind bind-utils

编辑/etc/named.conf,将options内去掉 listen-on port 53 { 127.0.0.1; }; listen-on-v6 port 53 { ::1; };这两项,如下:

options {
        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; };
        recursion yes;
        ......

编辑/etc/named.rfc1912.zones,在尾部添加如下内容:

zone "mingxiao.info" IN {
        type master;
        file "mingxiao.info.zone";
        allow-update { none; };
        allow-transfer { none; };
};
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.1.zone";
        allow-update { none; };
        allow-transfer { none; };
};

新建/var/named/mingxiao.info.zone  并添加如下内容:

$TTL 86400
@       IN      SOA     ns.mingxiao.info        admin.mingxiao.info. (
                        20150526
                        2H
                        10M
                        3D
                        1D )
        IN      NS      ns
        IN      MX 10   mail
ns      IN      A       192.168.1.110
mail    IN      A       192.168.1.110

新建/var/named/192.168.1.zone  并添加如下内容

$TTL 86400
@       IN      SOA     ns.mingxiao.info        admin.mingxiao.info. (
                        20150526
                        2H
                        10M
                        3D
                        1D )
        IN      NS      ns.mingxiao.info.
110      IN      PTR     ns.mingxiao.info.
110      IN      PTR    mail.mingxiao.info.

更改权限及属组

[[email protected] named]# chmod 640 /var/named/mingxiao.info.zone

[[email protected] named]# chmod 640 /var/named/192.168.1.zone

[[email protected] named]# chgrp named 192.168.1.zone mingxiao.info.zone

DNS指向自己主机

[[email protected] named]# echo "nameserver 192.168.1.110" > /etc/resolv.conf

启动named,并测试解析是否正常,请确保解析正常。

[[email protected] named]# service named start

[[email protected] named]# dit -t A mail.mingxiao.info

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -t A mail.mingxiao.info
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56173
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;mail.mingxiao.info. IN A

;; ANSWER SECTION:
mail.mingxiao.info. 86400 IN A 192.168.1.110

;; AUTHORITY SECTION:
mingxiao.info. 86400 IN NS ns.mingxiao.info.

;; ADDITIONAL SECTION:
ns.mingxiao.info. 86400 IN A 192.168.1.110

;; Query time: 0 msec
;; SERVER: 192.168.1.110#53(192.168.1.110)
;; WHEN: Mon Mar 30 16:19:25 2015
;; MSG SIZE  rcvd: 85

步骤2:安装mysql

[[email protected] ~]# yum install mysql-server mysql-devel

[[email protected] ~]# service mysqld restart

步骤3:安装postfix

编译安装postfix,首先关闭原先postfix,并改名即可。

[[email protected] ~]# service postfix stop

Shutting down postfix:

[[email protected] ~]# mv /etc/init.d/postfix /etc/init.d/postfix.old

删除原来的postfix用户及组,并重新添加。

[[email protected] ~]# userdel del postfix

[[email protected] ~]# groupadd -g 2525 postfix

[[email protected] ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

[[email protected] ~]# tar xf postfix-3.0.0.tar.gz

[[email protected] ~]# cd postfix-3.0.0

make makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ‘

‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto‘

make

make install

注意:make install 过程中会让您输入一些路径,全部敲回车使用默认即可。

提供SysV风格的服务启动脚本,新建/etc/init.d/postfix文件,并加入以下内容:

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program #              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ $NETWORKING = "no" ] && exit 3
[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6
RETVAL=0
prog="postfix"
start() {
# Start daemons.
echo -n $"Starting postfix: "
        /usr/bin/newaliases >/dev/null 2>&1
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
return $RETVAL
}
stop() {
  # Stop daemons.
echo -n $"Shutting down postfix: "
/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
echo
return $RETVAL
}
reload() {
echo -n $"Reloading postfix: "
/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
RETVAL=$?
echo
return $RETVAL
}
abort() {
/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
return $?
}
flush() {
/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
return $?
}
check() {
/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
return $?
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
  start)
start
;;
  stop)
stop
;;
  restart)
stop
start
;;
  reload)
reload
;;
  abort)
abort
;;
  flush)
flush
;;
  check)
check
;;
  status)
  status master
;;
  condrestart)
[ -f /var/lock/subsys/postfix ] && restart || :
;;
  *)
echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
exit 1
esac
exit $?
# END

[[email protected] postfix-3.0.0]# chmod +x /etc/init.d/postfix

[[email protected] postfix-3.0.0]# chkconfig postfix on

[[email protected] postfix-3.0.0]# service postfix start

Starting postfix:                                          [FAILED]

出现错误,首先查看日志

[[email protected] postfix-3.0.0]# tail /var/log/maillog

Mar 30 16:46:26 mail postfix/postfix-script[28627]: warning: not owned by postfix: /var/lib/postfix/./master.lock

Mar 30 16:46:26 mail postfix/postfix-script[28639]: starting the Postfix mail system

Mar 30 16:46:26 mail postfix/master[28643]: fatal: open lock file /var/lib/postfix/master.lock: cannot open file: Permission denied

Mar 30 16:46:27 mail postfix/master[28641]: fatal: daemon initialization failure

Mar 30 16:46:28 mail postfix/postfix-script[28644]: fatal: mail system startup failed

解决办法:

[[email protected] postfix-3.0.0]# rm -f /var/lib/postfix/./master.lock

[[email protected] postfix-3.0.0]# service postfix start

Starting postfix:                                          [  OK  ]

启动成功,查看日志,看有无错误警告信息。

[[email protected] ~]# newaliases

编辑/etc/postfix/main.cf配置文件,修改以下内容:

myhostname=mail.mingxiao.info

mydomain=mingxiao.info

myorigin=$mydomain

inet_interfaces=all

mydestination=$myhostname,localhost.$mydomain,localhost,$mydomain,ns.$mydomain

mynetworks=192.168.1.0/24,127.0.0.0/8

[[email protected] ~]# service postfix restart

[[email protected] ~]# telnet mail.mingxiao.info 25

Trying 192.168.1.110...
Connected to mail.mingxiao.info.
Escape character is ‘^]‘.
220 mail.mingxiao.info ESMTP Postfix
helo mail.mingxiao.info
250 mail.mingxiao.info
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>
How are you.
.
250 2.0.0 Ok: queued as 9A07960408
quit
221 2.0.0 Bye
Connection closed by foreign host.

查看日志发送状态信息:可以发现状态是delevered to mailbox,发送成功。

[[email protected] ~]# tail /var/log/maillog

Mar 30 17:02:46 mail postfix/local[29129]: 9A07960408: to=<[email protected]>, relay=local, delay=28, delays=28/0.02/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)

Mar 30 17:02:46 mail postfix/qmgr[29109]: 9A07960408: removed

Mar 30 17:02:49 mail postfix/smtpd[29121]: disconnect from ns.mingxiao.info[192.168.1.110] helo=1 mail=1 rcpt=1 data=1 quit=1 commands=5

切换到shubiao用户

[[email protected] ~]# su - shubiao

[[email protected] ~]$ mail

Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/shubiao": 1 message 1 new
>N  1 [email protected]  Mon Mar 30 17:02  13/503
& 1
Message  1:
From [email protected]  Mon Mar 30 17:02:46 2015
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Mon, 30 Mar 2015 17:02:18 +0800 (CST)
From: [email protected]
Status: R
How are you.

可以看到已经收到一封邮件。

在XP上用Outlook Express测试,使用shubiao账号登陆,给jianpan用户发送一封测试邮件:

[[email protected] ~]# su - jianpan

[[email protected] ~]$ mail

Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/jianpan": 1 message 1 new
>N  1 hi                    Mon Mar 30 17:25  44/1534  "test"
& 1
Message  1:
From [email protected]  Mon Mar 30 17:25:58 2015
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
From: "hi" <[email protected]>
To: <[email protected]>
Subject: test
Date: Mon, 30 Mar 2015 09:25:57 +0800
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0022_01D06ACB.879E7AC0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157
Status: R
Content-Type: text/plain;
charset="gb2312"
Hi.

收信成功,但此时尚不能在windows上收取邮件,远程用户接收邮件需要有MRA(mail retrieval agent)服务器,使用pop3或imap协议接收邮件,因此安装dovecot。

步骤4:安装dovecot

[[email protected] ~]# yum install dovecot

编辑/etc/dovecot/dovecot.conf,取消protocol并改为protocols = pop3

[[email protected] ~]# telnet mail.mingxiao.info 110

Trying 192.168.1.110...
Connected to mail.mingxiao.info.
Escape character is ‘^]‘.
+OK Dovecot ready.
USER jianpan
+OK
PASS jianpan
Connection closed by foreign host.

出错,查看日志报什么错误

[[email protected] ~]# tail /var/log/maillog

Mar 30 17:35:33 mail dovecot: pop3-login: Login: user=<jianpan>, method=PLAIN, rip=192.168.1.110, lip=192.168.1.110, mpid=29824, secured

Mar 30 17:35:33 mail dovecot: pop3(jianpan): Error: user jianpan: Initialization failed: mail_location not set and autodetection failed: Mail storage autodetection failed with home=/home/jianpan

Mar 30 17:35:33 mail dovecot: pop3(jianpan): Error: Invalid user settings. Refer to server log for more information.

解决办法:mail_location没有设置,在配置文件中设置即可,即为邮件存放位置。

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

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

[[email protected] ~]# telnet mail.mingxiao.info 110

Trying 192.168.1.110...
Connected to mail.mingxiao.info.
Escape character is ‘^]‘.
+OK Dovecot ready.
USER jianpan
+OK
PASS jianpan
-ERR [IN-USE] Couldn‘t open INBOX: Internal error occurred. Refer to server log for more information. [2015-03-30 17:38:04]
Connection closed by foreign host.

出错,查看日志,发现是权限问题。

Mar 30 17:38:04 mail dovecot: pop3-login: Login: user=<jianpan>, method=PLAIN, rip=192.168.1.110, lip=192.168.1.110, mpid=29869, secured

Mar 30 17:38:04 mail dovecot: pop3(jianpan): Error: chown(/home/jianpan/mail/.imap/INBOX, -1, 12(mail)) failed: Operation not permitted (egid=500(jianpan), group based on /var/mail/jianpan)

Mar 30 17:38:04 mail dovecot: pop3(jianpan): Error: mkdir(/home/jianpan/mail/.imap/INBOX) failed: Operation not permitted

Mar 30 17:38:04 mail dovecot: pop3(jianpan): Error: Couldn‘t open INBOX: Internal error occurred. Refer to server log for more information. [2015-03-30 17:38:04]

Mar 30 17:38:04 mail dovecot: pop3(jianpan): Couldn‘t open INBOX top=0/0, retr=0/0, del=0/0, size=0

解决方法:

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

mail_access_groups = mail

[[email protected] ~]# telnet mail.mingxiao.info 110

Trying 192.168.1.110...
Connected to mail.mingxiao.info.
Escape character is ‘^]‘.
+OK Dovecot ready.
USER jianpan
+OK
PASS jianpan
+OK Logged in.
LIST
+OK 2 messages:
1 1522
2 1526
.

可以使用dovecot接收邮件了。

测试发邮件给shubiao,在windows使用outlook express接收邮件是否成功。

[[email protected] postfix-3.0.0]# telnet 192.168.1.110 25
Trying 192.168.1.110...
Connected to 192.168.1.110.
Escape character is ‘^]‘.
220 mail.mingxiao.info ESMTP Postfix
helo mail.mingxiao.info
250 mail.mingxiao.info
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>
Hahaa!  
.

在outlook express点击接收所有邮件,发现仍是不允许,查看日志信息。

Mar 30 18:04:42 mail dovecot: pop3-login: Disconnected (tried to use disabled plaintext auth): rip=192.168.1.77, lip=192.168.1.110

Mar 30 18:05:00 mail dovecot: pop3-login: Disconnected (tried to use disabled plaintext auth): rip=192.168.1.77, lip=192.168.1.110

解决办法:编辑/etc/dovecot/conf.d/10-auth.conf,将disable_plaintext_auth = no

默认的是disable_plaintext_auth=yes,如果客户端没有配置使用SSL/TLS,就不得不设置成disable_plaintext_auth=no

重启dovecot服务,重新点击接收所有邮件。接收邮件成功。

基本邮件收发功能已经实现,下面要实现webmail功能...未完待续。

www.mingxiao.info

时间: 2024-11-08 23:45:40

RHEL6 postfix+dovecot 邮件服务配置的相关文章

搭建 Postfix、Dovecot 邮件服务

搭建 Postfix.Dovecot 邮件服务 准备域名 任务时间:15min ~ 20min 域名注册 如果您还没有域名,可以在腾讯云上选购,过程可以参考下面的视频. 视频 - 在腾讯云上购买域名 域名解析 域名购买完成后, 需要将域名解析到实验云主机上,实验云主机的 IP 为: <您的 CVM IP 地址> 在腾讯云购买的域名,可以到控制台添加解析记录,过程可参考下面的视频: 视频 - 如何在腾讯云上解析域名 完成该实验共需要添加两条记录: A 记录 记录类型:A 主机记录:@ 记录值:&

邮件服务配置(虚拟域&虚拟用户)

邮件服务配置(虚拟域&虚拟用户) 本文首发:https://www.somata.work/2019/VirtualMailServerConfig_MariaDB.html 现在我做的是:Linux + httpd + php + mariadb + postfix + dovecot + phpMyAdmin + postfixadmin + roundcubemail 这里我将会讲解 如何制作基于 虚拟域和虚拟用户 的邮件服务.需要的软件如下: phpMyAdmin-3.4.3-all-l

linux 第十八天学习(DNS分离解析、DHCP配置、邮件服务配置)

DNS分离解析技术 yum install bind-chroot systemctl restart named systemctl enable named vim /etc/named.conf vim /etc/named.rfc1912.zones 配置网卡 cd /var/named/ cp -a named.localhost dream.com.china cp -a named.localhost dream.com.american vim dream.com.china v

postfix之邮件服务基础知识

SMTP(Simple Mail Transfer Protocol)    smptd: TCP 25 服务端.    smtp: 客户端.随机端口,通常大于5000 SMTP状态码:        1xx 纯信息        2xx 正确        3xx 上一步操作尚未完成,待后续补充        4xx 暂时性错误        5xx 永久性错误 SMTP协议命令:        helo 以smtp协议向对方发送hello信息.        ehlo 以esmtp协议向对方

Linux的postfix邮件服务

一.postfix邮件服务 postfix提供smtp协议用来投递邮件默认端口25/var/log/maillog    服务日志mail [email protected]Subject: hellohello world .                           用"."来结束录入内容并发送mailq                  查看邮件队列postqueue -f      重新处理邮件队列 默认情况下邮件端口只在127.0.0.1上开启 二.环境配置 1.设

《Linux菜鸟入门2》空壳邮件服务

●空壳邮件 1.引入空壳邮件的意义 邮件服务器直接暴露在网络环境下安全性会大大降低,所以引入"空壳服务器"是为了保证真正服务器的安全,空壳服务器的功能就是将受到的邮件转发(双向的). 2.制作空壳邮件 在配置好DNS的前提下: 空壳服务器配置(maillinux.linux.com): vim /etc/named.rfc1912.zones cd /var/named/ cp -p westos.com.zone westos.org.zone vim westos.org.zone

邮件服务系列之三实现postfix+dovecot+sasl

MRA :cyrus-imap,dovecot dovecot 依赖MySQL客户端 pop3协议监听tcp110 imap4协议监听tcp143端口 以明文方式工作需结合sasl来实现邮件传输加密 dovecot支持四种协议: pop3 imap4 pop3s imaps 配置文件位于:/etc/dovecot.conf 带有sasl认证能力 支持两种邮箱格式: mbox一个文件存储所有邮件 maildir:一个文件存储一封邮件,所有邮件存储在一个目录中 安装: yum install dov

Postfix邮件服务器的原理和postfix + dovecot配置,使用Thunderbird发送邮件和SMTP认证

1.邮件的基本概念MUA:邮件用户代理,客户端收发邮件的软件MTA:邮件传输代理,服务器上的部署邮件服务器的软件MDA:邮件投递代理,在邮件服务器上将邮件存放到相应的位置MRA:邮件收取代理,为MUA读取邮件提供标准接口,主要使用POP3和IMAP协议2.常用的MUA与MTAMUA:Outlook.Mozilla Thunderbird.FoxmailMTA:Sendmail.Postfix.Qmail.Exchange Server3.邮件传递原理发送邮件时:   用户通过MUA将邮件投递到M

邮件服务Postfix+Sasl+Dovecot

环境: DNS:192.168.200.100 mail:192.168.200.101 Bind服务配置 安装Bind软件包. yum install -y bind Bind配置文件. vim /etc/named.conf 12 options { 13         listen-on port 53 { 192.168.200.100; }; 14         listen-on-v6 port 53 { ::1; }; 15         directory       "/