一安装准备与说明

服务器操作系统:Linux (centos 6.2)

postfix 、dovecot 版本:直接使用 yum 安装即可。

postfix 根目录:/etc/postfix

dovecot 根目录:/etc/dovecot

假设你的邮箱使用域名为:mailtest.cn 需要对该域名进行解析操作(增加 mx 解析记录)

假设服务器IP:123.123.123.123(备注:外网IP)

需要开放的端口:25、110、143

mysql数据库相关信息

数据库host:127.0.0.1(根据msql所在服务器实际IP填写,此处只是举例)

数据库端口: 3306 (必须是 3306)

数据库名称:mailserver

数据库用户: root

数据库密码: 123456

解析操作:为域名mailtest.cn 新增一条 mx 解析记录,并且该记录指向IP:123.123.123.123

postfix 仅提供 smtp 服务,不提供 pop3 和 imap 服务,主要是用发送和接收邮件的(接收到的邮件后,一般转交 dovecot 处理,dovecot 负责将 postfix 转发过来的邮件保存到服务器硬盘上)

dovecot 仅提供 pop3 和 imap 服务,不提供 smtp 服务(Foxmail之类的邮箱客户端,都是通过pop3 和 imap 来收发邮件的。发邮件时,dovecot 会将邮件转交给 postfix 来发送)

综上,postfix 用来发邮件,dovecot 用来收邮件

( 重要!) postfix发送邮件的日志文件:/var/log/maillog

二基本配置步骤

1主机名hostname配置(必须)

1.1 修改主机名:

[root@a ~] vi /etc/sysconfig/network

修改 HOSTNAME=mx.mailtest.cn 并保存,然后重启服务器。如果没有重启服务器,更改主机名不会生效

1.2检测主机名

[root@root ~] hostname

mail.devstore.cn

1.3开放防火墙中的 25、110、143 端口

[root@root ~] /sbin/iptables -I INPUT -p tcp --dport 25-j ACCEPT

[root@root ~] /sbin/iptables -I INPUT -p tcp --dport 110-j ACCEPT

[root@root ~] /sbin/iptables -I INPUT -p tcp --dport 143-j ACCEPT

[root@root ~] service iptables save

[root@root ~] service iptables restart

2. SELinux设置

2.1查看SELinux状态

[root@root ~] /usr/sbin/sestatus -v

( 查看SELinux是否开启。如果不是显示:    SELinux status: disabled    则代表着SELinux处于开启状态  )

2.2关闭SELinux的操作:

[root@root ~] vi /etc/selinux/config

将 SELINUX=enforcing 改为 SELINUX=disabled ,然后重启机器(必须重启,修改才能生效)。重启后再查看一次状态,看看SELinux是否已经关闭

3 安装postfix

centos 6.2 默认已经安装了 postfix ( postfix根目录:/etc/postfix)

3.1 postfix状态查看

[root@root ~] service postfix status

master (pid 4366) 正在运行...

3.2查看系统 MTA

[root@root ~] alternatives --display mta (查看系统 MTA:邮件传送端,即常说的邮件服务器是否为postfix )

mta - 状态是自动。

链接目前指向/usr/sbin/sendmail.postfix

/usr/sbin/sendmail.postfix - 优先度 30

从 mta-mailq:/usr/bin/mailq.postfix

从 mta-newaliases:/usr/bin/newaliases.postfix

从 mta-pam:/etc/pam.d/smtp.postfix

从 mta-rmail:/usr/bin/rmail.postfix

从 mta-sendmail:/usr/lib/sendmail.postfix

从 mta-mailqman:/usr/share/man/man1/mailq.postfix.1.gz

从mta-newaliasesman:/usr/share/man/man1/newaliases.postfix.1.gz

从 mta-sendmailman:/usr/share/man/man1/sendmail.postfix.1.gz

从 mta-aliasesman:/usr/share/man/man5/aliases.postfix.5.gz

当前"最佳"版本是/usr/sbin/sendmail.postfix。

(sendmail.postfix 说明当前 MTA 的确就是 postfix )

4安装postfix和dovecot插件

[root@root ~] yum -y install postfix* dovecot*

5 用户管理

创建 vmail 用户

[root@root ~] groupadd -g 2000 vmail       ( 指定新建用户组vmail的ID为2000  )

[root@root ~] useradd -g vmail -u 2000 vmail -d/var/vmail       ( 指定新建用户vmail的ID为2000,用户根目录为/var/vmail  )

[root@root ~] chown -R vmail:dovecot /etc/dovecot

[root@root ~] chmod -R o-rwx /etc/dovecot

6创建数据表

6.1mailserver数据库需要新建1张表。表结构参照如下:

CREATE TABLE `tb_user_email` (

`id` bigint(20)NOT NULL AUTO_INCREMENT,

`user_id`bigint(20) NOT NULL,

`username`varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '用户邮箱名',

`domain`varchar(255) CHARACTER SET utf8 NOT NULL COMMENT '用户的邮箱域名',

`password`varchar(255) CHARACTER SET utf8 NOT NULL,

`home`varchar(255) CHARACTER SET utf8 DEFAULT NULL,

`uid` int(11)DEFAULT NULL,

`gid` int(11)DEFAULT NULL,

`active` char(1)CHARACTER SET utf8 NOT NULL DEFAULT 'Y',

`create_time`datetime NOT NULL COMMENT '创建时间',

`create_user_id`bigint(20) DEFAULT NULL COMMENT '创建用户id',

`last_update_time` datetime DEFAULT NULL COMMENT '最后一次修改时间',

`last_update_user_id` bigint(20) DEFAULT NULL COMMENT '最后一次修改的用户id',

`curr_type`int(5) NOT NULL DEFAULT '1' COMMENT '当前状态',

`source`varchar(100) CHARACTER SET utf8 DEFAULT NULL,

`destination`varchar(100) CHARACTER SET utf8 DEFAULT NULL,

`type` int(5) NOTNULL COMMENT '邮箱类型 1iClap个人邮箱 2私有域名邮箱',

PRIMARY KEY(`id`),

KEY `user_id`(`user_id`) USING BTREE

) ENGINE=InnoDB AUTO_INCREMENT=632 DEFAULT CHARSET=utf8COLLATE=utf8_unicode_ci;

6.2表结构需要额外说明的列:

active: 账号是否“激活”状态,默认为Y

domain:postfix会检查接收到的邮件域名是否合法,及@后面的字符串

6.3关于表中密码列 password 的值的说明

e10adc3949ba59abbe56e057f20f883e  是 123456 的MD5加密后的值

25f9e794323b453885f5181f1b624d0b  是 123456789 的MD5加密后的值

7为 postfix 配置<用户账号、域名>验证功能

7.1新建 /etc/postfix/mysql-virtual-mailbox-domains.cf  文件

hosts = 127.0.0.1

user = root

password = 123456

dbname = mailserver

query = SELECT 1 FROM tb_user_email  WHERE domain='%s'

# %s代表:域名

7.2新建 /etc/postfix/mysql-virtual-mailbox-maps.cf  文件

hosts = 127.0.0.1

user = root

password = 123456

dbname = mailserver

query = SELECT 1 FROM tb_user_email  WHERE username='%u'

# %u  代表:用户账号

7.3新建  /etc/postfix/mysql-virtual-alias-maps.cf  文件

hosts = 42.51.172.27

user = root

password = devdb

dbname = dev_store

query = SELECT destination FROMuser_enterprise_email  WHERE source='%s'

# %s  代表:域名

后续会有测试命令可以测试以上配置是否正确

三配置 postfix + smtp 服务

1修改/etc/postfix/main.cf 文件(注意,以下配置内容中,等于号 = 的左右 都必须有 空格):

[root@root ~] cd /etc/postfix/

[root@root postfix] vi main.cf

myhostname = mail.devstore.cn    #Mail服务器域名,EHLO名称。邮箱名称 ( xxx@mail.devstore.cn )  (主机名hostname的值必须和这个相同,否则会报错的)

mydomain = devstore.cn   #邮箱域名 (xxx@devstore.cn )。必要的时候,你也可以设置成 mydomain =mail.devstore.cn ( xxx@mail.devstore.cn )

myorigin = $mydomain

inet_interfaces = all   #如果 inet_interfaces= localhost,则邮箱不接收外网的邮件,只接受内网的邮件。inet_interfaces= all 则邮箱会接收外网的邮件

mydestination = localhost    #本地邮件域名,直接接收

mynetworks = 127.0.0.0/8     #116.255.217.0/28,127.0.0.0/8    #允许转发的来源IP,该值设置后,mynetworks_style 参数将被忽略掉

relay_domains = $mydestination

virtual_transport = lmtp:unix:private/dovecot-lmtp       ( 这个配置非常重要,是psotfix 将接收到的邮件转交给 dovecot 处理的关键配置 )

virtual_mailbox_maps =mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf       ( 下面这3个文件就是调用刚才新创建的那3个文件来连接mysql 数据库的  )

virtual_alias_maps =mysql:/etc/postfix/mysql-virtual-alias-maps.cf

virtual_mailbox_domains =mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf

smtpd_sasl_type = dovecot

smtpd_sasl_path = private/auth

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination, permit

broken_sasl_auth_clients = yes

#限制每一封邮件最大容量为 20M

#message_size_limit = 20480000

#限制postfix 最大并发连接数

#default_process_limit = 100

修改好文件后,保存并退出。然后重启psotfix:service postfixrestart

四配置 dovecot + pop3 +imap

配置 dovecot 需要修改以下 8 个文件 ( dovecot根目录:/etc/dovecot ):

/etc/dovecot/dovecot.conf                        Dovecot的主配置文件

/etc/dovecot/conf.d/10-auth.conf                  用户验证相关配置信息

/etc/dovecot/conf.d/10-mail.conf                   Dovecot将要操作的磁盘路径相关配置信息

/etc/dovecot/conf.d/10-master.conf                 Dovecot本地socket相关配置信息

/etc/dovecot/conf.d/10-ssl.conf                     关于SSL的相关配置信息

/etc/dovecot/conf.d/20-pop3.conf                   关于POP3的相关配置信息

/etc/dovecot/conf.d/auth-sql.conf.ext                 SQL-Type验证相关配置信息

/etc/dovecot/dovecot-sql.conf.ext            Dovecot与数据库连接相关配置信息。example文件位置:/usr/share/doc/dovecot-2.0.9/example-config/

1 [root@root dovecot] vi/etc/dovecot/dovecot.conf
[root@root dovecot] vi /etc/dovecot/dovecot.conf

protocols = imap pop3 lmtp

2 [root@root dovecot] vi /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login

#禁止系统用户登录 ( 在 !include auth-system.conf.ext 前面加个 # 号 )

#!include auth-system.conf.ext

#启用mysql中的用户 ( 把  #!include auth-sql.conf.ext 前面的 # 号删除掉 )

!include auth-sql.conf.ext

3 [root@root dovecot] vi/etc/dovecot/conf.d/10-mail.conf

mail_location = maildir:/var/vmail/%d/%n

mail_privileged_group = vmail

# namespace inbox 会因为dovecot 的版本不同而有所改变

# Error: user xxx@mail.devstore.cn: Initializationfailed: namespace configuration error: inbox=yes namespace missing

# 如果系统日志/var/log/maillog中报上面的错误,则加入以下内容

namespace inbox {

inbox = yes

}

4 [root@root dovecot] vi/etc/dovecot/conf.d/10-master.conf

#-------------------------------------------------------------可选操作 begin-----------------------------------------------------------------------------------

#通过将端口设置为0,以禁用非SSL加密的IMAP和POP3协议

service imap-login {

inet_listener imap {

port = 0

}

...

}

service pop3-login {

inet_listener pop3 {

port = 0

}

...

}

#-------------------------------------------------------------可选操作 end-----------------------------------------------------------------------------------

# 这个配置非常重要,是用来接收psotfix 转交过来的邮件的关键配置

service lmtp {

unix_listener /var/spool/postfix/private/dovecot-lmtp {

mode = 0600

user = postfix

group = postfix

}

#inet_listener lmtp {

#Avoid making LMTP visible for the entire internet

#address =

#port =

#}

service auth {

unix_listener /var/spool/postfix/private/auth {

mode = 0666

user = postfix

group = postfix

}

unix_listener auth-userdb {

mode = 0600

user = vmail

#group =

}

# Auth process is run as this user.

user = dovecot

}

service auth-worker {

user = vmail

}

5 [root@root dovecot] vi/etc/dovecot/conf.d/10-ssl.conf

ssl = no

6 [root@root dovecot] vi /etc/dovecot/conf.d/20-pop3.conf

pop3_uidl_format = %08Xu%08Xv

pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

7 [root@root dovecot] vi/etc/dovecot/conf.d/auth-sql.conf.ext

passdb {

driver = sql

args = /etc/dovecot/dovecot-sql.conf.ext

}

#userdb {

# driver = sql

# args = /etc/dovecot/dovecot-sql.conf.ext

#}

userdb {

driver = static

args = uid=vmail gid=vmail home=/var/vmail/%d/%n

#注意这里的 home需要和 mail_location 配置的值相同 ( mail_location 在10-mail.conf 文件中 )

}

8 [root@root dovecot] vi /etc/dovecot/dovecot-sql.conf.ext

(dovecot-sql.conf.ext文件所在位置:/usr/share/doc/dovecot-2.0.9/example-config/dovecot-sql.conf.ext,请先下载此文件后,再执行编辑vi命令)

driver = mysql

connect = host=172.10.2.162 dbname=mailserver user=rootpassword=123456

default_pass_scheme = MD5    #  (default_pass_scheme是指用户的密码的加密方式:对应users表中password列的值 )

#default_pass_scheme = PLAIN  #明文,不加密

#PLAIN: Password is in plaintext.

#CRYPT: Traditional DES-crypted password in /etc/passwd(e.g. "pass" = vpvKh.SaNbR6s)

#Dovecot uses libc's crypt() function, which means thatCRYPT is usually able to recognize MD5-CRYPT and possibly also other passwordschemes. Please see the notes below regarding glibc's crypt() and SHA-256/512support.

#The traditional DES-crypt scheme only uses the first 8characters of the password, the rest are ignored. Other schemes may have otherpassword length limitations (if they limit the password length at all).

#MD5-CRYPT: MD5 based salted password hash nowadayscommonly used in /etc/shadow. (e.g. "pass" =$1$ozdpg0V0$0fb643pVsPtHVPX8mCZYW/)

#MD5: Alias for MD5-CRYPT. Dovecot versions earlier thanv1.0.rc16 need to use this instead of MD5-CRYPT. This name is deprecatedbecause MD5-CRYPT isn't an actual MD5 hash.

#PLAIN-MD5: An actual MD5 hash of the password. (e.g."pass" = 1a1dc91c907325c69271ddf0c944bc72)

上面 8个文件修改完成后:

重启 dovecot
[root@root postfix] service dovecot restart

重启 postfix
[root@root dovecot] service postfix restart

到此为止,postfix和dovecot都配置好了,并且启用了 smtp、pop3、imap 服务

[root@root dovecot] cat /var/log/maillog       查看日志.

邮件系统安装配置(postfix + dovecot)相关推荐

  1. centos dovecot mysql_Centos6.4 配置postfix+dovecot+mysql

    使用Linux用户验证和收发邮件 需要组件 postfix dovecot roundcube postfix 用来收发邮件, 作为SMTP服务器, 监听25端口 dovecot 用作为POP3, I ...

  2. linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(二)-基于mysql的虚拟账户登陆收发邮件...

    linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(二)-基于mysql的虚拟账户登陆收发邮件 使用虚拟用户收发邮件安装 九.安装Courier authentication lib ...

  3. 配置postfix+dovecot+mysql+postfixadmin+squirrelmail 邮件系统笔记

    最近想搭建一个完整的mailserver,查了很多资料,一直没有成功,网上大部分资料是在redhat系列的操作系统上的,而且很多都是采用rpm包. 我现在的系统是suse Linux有许多包已经安装, ...

  4. linux mysql 邮件_linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(二)-基于mysql的虚拟账户登陆收发邮件...

    linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(二)-基于mysql的虚拟账户登陆收发邮件 使用虚拟用户收发邮件安装 九.安装Courier authentication lib ...

  5. linux用户无法接收邮件,linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(一)-系统账户登陆收发邮件...

    linux 下 搭建邮件邮件服务器(一)-系统账户登陆收发邮件 一.安装环境# lsb_release -d Description:    CentOS release 6.5 (Final) #  ...

  6. hMailServer 邮件系统安装配置篇

    此篇进入正题,详细的说一下安装和配置过程.得先说一下,hMailServer是真正的邮件服务端,而Roundcube Webmail仅仅是为hMailServer提供Webmail应用的,可以让你通过 ...

  7. linux邮件自动回复,debian上 postfix+dovecot+squirrelmail 实现 自动回复

    作者:lxq007 本文主要介绍了基于dovecot 的邮件自动回复 的配置过程. 我使用的系统及安装的软件包为Debian GNU/Linux 4.0.postfix 2.3.4-3 .squirr ...

  8. CentOS 搭建Postfix+Dovecot简单邮件系统

    2019独角兽企业重金招聘Python工程师标准>>> 服务器信息 系统:CentOS 6.5 minimal版本 主机:虚拟机 虚拟机IP:192.168.128.128/24 宿 ...

  9. Postfix邮件系统安装与配置:Postfix,Cyrus-IMAP,Cyrus-sasl,Dovecot和SPF

    最近发现邮件发送服务还是挺重要的.可能对于每天只有一百来封的邮件发送需求的个人博主来说,一个免费的邮箱提供的免费SMTP邮件发送服务就可以满足了,但是对于一些大型的网站.论坛和平台,每天的邮件发送量可 ...

  10. LAMP+Postfix+Dovecot+Postfixadmin搭建邮件管理系统(六)

    接上期,我们部署完了Postfix服务,下面开始部署Dovecot服务. 七.部署Dovecot服务 1.下载dovecot安装包 [root@Mail ~]# wget -c https://dov ...

最新文章

  1. 中国矿业大学计算机学院机房,2020年中国矿业大学计算机学院初试自命题科目考试大纲-数据结构...
  2. Web访问RabbitMQ
  3. 解决Eclipse狂吃内存的解决方法(转)
  4. 呢篇唔系教程 -- 记录自己第一次Android刷机
  5. 【Verilog语法】读文件
  6. java 读取 文本块_Java 13:文本块
  7. JDBC Statements, PreparedStatement
  8. 网络 传输层 | UDP协议与TCP协议详解(三次握手及四次挥手、滑动窗口、拥塞控制)
  9. 利用DBMS_ROWID.ROWID_CREATE来找出事务等待的行数据
  10. 大象的崛起!Hadoop七年发展风雨录
  11. windows10补丁包离线更新
  12. 微信如何添加企业微信信息服务器地址,企业微信和微信消息怎么互通_企业微信和微信消息互通操作流程一览...
  13. 重言式判定------参考了别人的代码。。
  14. 4.12作业--CSS
  15. 思科设备VLAN配置命令
  16. 诗词欣赏,沁园春政治与经济
  17. python爬虫--破解js加密:kankan登录破解
  18. 最新版TCGA 矩阵整理,百分百复现成功
  19. c语言程序设计上机总结,C语言程序设计上机实践心得报告.doc
  20. 生活中有趣好玩的产品设计

热门文章

  1. 17家IT初创公司失败史
  2. Spring @Validate 报 :No validator could be found for type 异常解決
  3. 我的博客转到http://wangxin19871010.blog.163.com/
  4. 装饰模式 DecoratePattern
  5. 飓风“桑迪”的蝴蝶效应:扇起桑迪域名注册潮
  6. 亚信安全发现勒索软件新变种Word文档成为导火索
  7. mysql单数据库多硬盘配置_MySQL 使用mysqld_multi部署单机多实例详细过程
  8. favicon.ico在线转换网站
  9. 光纤接头的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  10. vue-quill-editor超链接bug问题