邮件服务器搭建

1.前期准备

1.1设置hostname

debian11,可以通过hostnamectl set-hostname hostname命令设置hostname,或者修改/etc/hostname文件

hostnamectl set-hostname mail.sijibao.info

为什么要设置hostname呢?因为一般情况下,Postfix在与其他的SMTP服务器进行通信的时候,会使用hostname来表名自己的身份.
主机名有两种形式,单名字与FQDN(Fully Qualified Domain Name).如果SMTP服务器不是用FQDN来表明身份,则有可能会被拒收.

1.2修改防火墙开放端口

打开防火墙开发相应的端口,分别是25, 465, 110, 995, 143, 993

发邮件协议和端口:
  • 非加密端口:
    25端口(SMTP):25端口为SMTP(Simple Mail Transfer Protocol,简单邮件传输协议)服务所开放的,是用于发送邮件。
  • 加密端口:
    465端口(SMTP SSL):465端口是为SMTP SSL(SMTP-over-SSL)协议服务开放的,这是SMTP协议基于SSL安全协议之上的一种变种协议,它继承了SSL安全协议的非对称加密的高度安全可靠性,可防止邮件泄露。
收邮件协议和端口:
  • 非加密端口
    143端口(IMAP):143端口是为IMAP(INTERNET MESSAGE ACCESS PROTOCOL)服务开放的,是用于接收邮件的。
    110端口(POP3):110端口是为POP3(Post Office Protocol Version 3,邮局协议3)服务开放的,是用于接收邮件的
  • 加密端口:
    993端口(IMAP SSL):993端口是为IMAP SSL(IMAP-over-SSL)协议服务开放的,这是IMAP协议基于SSL安全协议之上的一种变种协议,它继承了SSL安全协议的非对称加密的高度安全可靠性,可防止邮件泄露。
    995端口是为POP3 SSSL(POP3-over-SSL)协议服务开放的,这是POP3协议基于SSL安全协议之上的一种变种协议,它继承了SSL安全协议的非对称加密的高度安全可靠性,可防止邮件泄露
    要收邮件必须打开25端口

1.3设置DNS MX记录和A记录

@         MX       mail.domain.com
mail      A        12.34.56.78

其中@符号表示主机名为空,相当于domain.com。第一条MX记录指定了domain.com这个域名的邮件服务器主机名。它的意思是:如果收件人邮箱地址@符号后面的域名是domain.com,那么发件人的MTA要将邮件投递到mail.domain.com这个主机。第二条A记录将mail.domain.com解析成IP地址。

例如,我的邮箱地址是[email protected],邮箱地址@符号后面的域名是linuxbabe.com。在你给我发邮件时,你的MTA首先查询DNS MX记录,“哦,原来是mail.linuxbabe.com这个主机负责linuxbabe.com的邮件呀”。然后你的MTA将查询mail.linuxbabe.com主机的IP地址,也就是从A记录找到mail.linuxbabe.com主机的IP地址,从而可以投递成功。

1.4创建系统用户

我们创建一个新的用户组以及用户,用来处理邮件.所有的虚拟邮箱,都会存在这个用户的home目录下

groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m

1.5创建mail数据库用以处理邮件相关的业务.并且创建邮件管理员

创建mail数据库用以处理邮件相关的业务.并且创建邮件管理员.

GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost' IDENTIFIED BY 'mys123456';
FLUSH PRIVILEGES;

mail数据库中一共有3个表,分别是虚拟域名, 用户信息, 邮件转发.

create database mail;

CREATE TABLE `domains` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`domain_id` int(11) NOT NULL,
`password` varchar(106) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
);

CREATE TABLE `aliases` (
`id` INT NOT NULL AUTO_INCREMENT,
`domain_id` INT NOT NULL,
`source` varchar(100) NOT NULL,
`destination` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
);

在虚拟域名表中插入域名

INSERT INTO `mail`.`domains`
(`id` ,`name`)
VALUES
('1', 'sijibao.info'),
('2', 'mail.sijibao.info');

在用户 信息表中插入用户

INSERT INTO `mail`.`users`
(`id`, `domain_id`, `password` , `email`)
VALUES
('1', '1', SHA('123123'), '[email protected]'),
('2', '1', SHA('123123'), '[email protected]');

设置别名

INSERT INTO `mail`.`aliases`
(`id`, `domain_id`, `source`, `destination`)
VALUES
('1', '1', '[email protected]', '[email protected]'),
('2', '1', '[email protected]', '[email protected]');

检查是否有数据

SELECT * FROM mail.domains;
SELECT * FROM mail.users;
SELECT * FROM mail.aliases;

2.安装postfix和dovecot

2.1安装postfix

apt-get install postfix postfix-mysql
  • 安装过程中需要选择Postfix的类型,请选择Internet Site:


    image.png

    No configuration 表示不要做任何配置;
    Internet Site 表示直接使用本地SMTP服务器发送和接收邮件;
    Internet with smarthost 表示使用本地SMTP服务器接收邮件,但发送邮件时不直接使用本地SMTP服务器,而是使用第三方smart host来转发邮件;
    Satellite system 表示邮件的发送和接收都是由第三方smarthost来完成。
    Local only 表示邮件只能在本机用户之间发送和接收。

  • 在第二个页面填入你的域名,也就是邮箱地址@符号后面的域名,这里随便写也可以,反正后面需要修改配置文件


    image.png

2.2安装dovecot

apt-get install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql

3.配置postfix和dovecot

3.1配置postfix

postfix主要修改两个文件:
master: /etc/postfix/master.cf (主进程的配置文件)
mail: /etc/postfix/main.cf (功能性配置文件)
先备份这个文件

cp /etc/postfix/main.cf /etc/postfix/main.cf.org
cp /etc/postfix/master.cf /etc/postfix/master.cf.org
  • 修改main.cf
    修改ssl证书地址,smtpd_tls_key_file和smtpd_tls_cert_file
smtpd_tls_key_file = /etc/letsencrypt/live/test.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/test.com/fullchain.pem

在smtpd_tls_security_level=may下加上

smtpd_use_tls=yes
smtpd_tls_auth_only = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes 

把myhostname的值设置对应域名MX记录的主机名

myhostname = mail.test.com

Postfix可以负责多个域名的邮件收发业务。我们就是通过mydetination这个参数来指定这些域名。这篇教程只考虑一个域名的邮件收发业务。Postfix在安装过程中,会自动添加localhost.locadomain和localhost到mydestination的值中,这是为了方便本机用户之间的邮件发送,将mydestination的值修改为localhost,以便Postfix能够通过MySQL表中相关数据决定需要接受/发送邮件的域名,这样更具有通用性。

mydestination = localhost

完整配置如下

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2



# TLS parameters
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_key_file = /etc/letsencrypt/live/test.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/test.com/fullchain.pem
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_use_tls=yes
smtpd_tls_auth_only = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes 


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination


myhostname = mail.test.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
#mydestination = $myhostname, test.com, racknerd-e8178, localhost.localdomain, localhost
mydestination = localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

virtual_transport = lmtp:unix:private/dovecot-lmtp

virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf

postfix配置文件解释:

mydomain参数是指email服务器的域名,请确保为正式域名(如sijibao.info)
myhostname参数是指系统的主机名称(如我的服务器主机名称是mail.sijibao.info)
myorigin参数指定本地发送邮件中来源和传递显示的域名。
myorigin = $mydomain 设置由本机寄出的邮件所使用的域名或主机名称
mynetworks参数指定受信任SMTP的列表,具体的说,受信任的SMTP客户端允许通过Postfix传递邮件。0.0.0.0/0 #配置这一项使用用户可在任意地发送邮件 
mydestination参数指定哪些邮件地址允许在本地发送邮件。这是一组被信任的允许通过服务器发送或传递邮件的IP地址。
用户试图通过发送从此处未列出的IP地址的原始服务器的邮件将被拒绝。
inet_interfaces参数设置网络接口以便Postfix能接收到邮件。
relay_domains:该参数是系统传递邮件的目的域名列表。如果留空,我们保证了我们的邮件服务器不对不信任的网络开放。
home_mailbox:该参数设置邮箱路径与用户目录有关,也可以指定要使用的邮箱风格。 
message_size_limit = 52428800 ###限制附件大小 
mailbox_size_limit = 209715200 ###容量大小 
注意:默认postfix从mydestination和virtual_mailbox_domains两个参数来确定postfix需要接收哪些域的邮件。
如果接收的邮件域与mydestination匹配,则使用系统帐号处理邮件;
如果接收的邮件域与virtual_mailbox_domains匹配则使用虚拟帐号处理邮件。
alias_maps = hash:/etc/aliases   在具有NIS的系统上,缺省值是搜索本地别名数据库,然后搜索NIS别名数据库。
不设置会有 warning: dict_nis_init: NIS domain name not set - NIS lookups disabled

smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem   你希望使用自己的SSL证书,私钥路径,则把/etc/pki/dovecot/private/dovecot.pem替换成你的证书路径.
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem    你希望使用自己的SSL证书,公钥路径,则把/etc/pki/dovecot/certs/dovecot.pem替换成你的证书路径.
smtpd_sasl_auth_enable = yes     //使用SMTP认证  
smtpd_sasl_security_options = noanonymous //取消匿名登陆方式 
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设定邮件中有关收件人部分的限制  
smtpd_sasl_type = dovecot smtp使用dovecot验证
smtpd_use_tls=yes     向远程SMTP客户端宣布STARTTLS支持,但不要求客户端使用TLS加密
smtpd_tls_auth_only = yes  当Postfix SMTP服务器中的TLS加密是可选的时,请勿通过未加密的连接通告或接受SASL认证。

virtual_transport = dovecot 以dovecot 默认邮件传递传输和下一跳的目标
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf  /读取数据库虚拟域 
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf     查询包含与$ virtual_mailbox_domains匹配的域中的所有有效地址。
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-virtual-email2email.cf
用于将特定邮件地址或域别名混合到其他本地或远程地址

更多配置信息参数的含义,请参照Postfix配置文档

  • 修改master.cf
    打开下面注释
submission inet n       -       y       -       -       smtpd
smtps     inet  n       -       y       -       -       smtpd
-o smtpd_tls_wrappermode=yes

3.2创建配置文件

创建虚拟域名配置

vim /etc/postfix/mysql-virtual-mailbox-domains.cf 
user = mail_admin
password = mys123456
hosts = 127.0.0.1
dbname = mail
query = SELECT 1 FROM domains WHERE name='%s'

创建虚拟邮箱配置

vim /etc/postfix/mysql-virtual-mailbox-maps.cf 
user = mail_admin
password = mys123456
hosts = 127.0.0.1
dbname = mail
query = SELECT 1 FROM users WHERE email='%s'

创建电子邮件与文件映射

vim /etc/postfix/mysql-virtual-alias-maps.cf 
user = mail_admin
password = mys123456
hosts = 127.0.0.1
dbname = mail
query = SELECT destination FROM aliases WHERE source='%s'

重启postfix

service postfix restart

测试文件是否调用成功

postmap -q sijibao.info mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
1
postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
1
postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-alias-maps.cf
[email protected]

重启postfix

systemctl restart  postfix.service

4.测试本地邮件服务是否正常

4.1 smtp协议命令源语

helo (smtp协议)
ehlo(esmtp协议)

mail from:senduser  指定发件人信息
rcpt to:reciver             指定收件人信息      对于公共邮箱必须有域名、A纪录、PTR解析。
data                    指定发送的信息

4.2 测试

telnet 127.0.0.1 25
helo mail.sijibao.info
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with .
This is a test mail from root.
.
250 2.0.0 Ok: queued as 3E55D20DCF12
quit  
221 2.0.0 Bye
[root@mail conf.d]#  mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
3E55D20DCF12      355 Fri Jun 15 14:57:01  [email protected]

5配置dovecot

备份文件

#fDovecot将要操作的磁盘路径相关配置信息
cp /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf.org
#用户验证相关配置信息
cp /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.org
#SQL-Type验证相关配置信息
cp /etc/dovecot/conf.d/auth-sql.conf.ext /etc/dovecot/conf.d/auth-sql.conf.ext.org
#Dovecot与数据库连接相关配置信息
cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext.org
#fDovecot本地socket相关配置信息
cp /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf.org
#关于SSL的相关配置信息
cp /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf.org

配置10-mail.conf

开文件并找到mail_location相关信息,将其指定到本地磁盘的某个路径,这个路径将来会存放收到的邮件,如下所示:

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

同时,找到文件中mail_privileged_group相关信息并将起修改为:

mail_privileged_group = mail

配置10-auth.conf

找到文件中disable_plaintext_auth并取消注释

disable_plaintext_auth = yes

找到文件中auth_mechanisms并将其修改为如下值:

auth_mechanisms = plain login

默认情况下,Dovecot是允许Ubuntu系统用户登录使用的,我们需要将其禁用。找到文件种如下内容并将其注释:

#!include auth-system.conf.ext

开启Dovecot的MySQL支持,取消!include auth-sql.conf.ext的注释符号:

#!include auth-system.conf.ext  
!include auth-sql.conf.ext  
#!include auth-ldap.conf.ext  
#!include auth-passwdfile.conf.ext  
#!include auth-checkpassword.conf.ext  
#!include auth-vpopmail.conf.ext  
#!include auth-static.conf.ext

配置auth-sql.conf.ext

vim /etc/dovecot/conf.d/auth-sql.conf.ext
passdb {
  driver = sql

  # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
  args = /etc/dovecot/dovecot-sql.conf.ext
}

# "prefetch" user database means that the passdb already provided the
# needed information and there's no need to do a separate userdb lookup.
# 
#userdb {
#  driver = prefetch
#}

userdb {
  #driver = sql
  #args = /etc/dovecot/dovecot-sql.conf.ext
  driver = static
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n
}

# If you don't have any user-specific settings, you can avoid the user_query
# by using userdb static instead of userdb sql, for example:
# 
#userdb {
  #driver = static
  #args = uid=vmail gid=vmail home=/var/vmail/%u
#}

配置/etc/dovecot/dovecot-sql.conf.ext

取消文件中driver行的注释,并将其修改为如下:

driver = mysql

取消文件中connect行的注释,并将其修改为如下:

connect = host=127.0.0.1  dbname=mail user=mail_admin password=123456

取消文件中default_pass_scheme行的注释,并将其修改为如下:

default_pass_scheme = SHA

取消文件中password_query行的注释,并将起修改为如下:

password_query = SELECT email as user, password FROM users WHERE email='%u';

配置/etc/dovecot/conf.d/10-master.conf

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

service imap-login {  
    inet_listener imap {  
        port = 0   
    }  
    ...  
}  

service pop3-login {  
    inet_listener pop3 {  
        port = 0  
    }  
    ...  
}

找到文件中的service lmtp并将其修改如下:

service lmtp {  
        unix_listener /var/spool/postfix/private/dovecot-lmtp {  
        mode = 0600  
        user = postfix  
        group = postfix  
  } 

找到文件中service auth并将其内容修改如下:

service auth {  
    # auth_socket_path points to this userdb socket by default. It's typically  
    # used by dovecot-lda, doveadm, possibly imap process, etc. Its default  
    # permissions make it readable only by root, but you may need to relax these  
    # permissions. Users that have access to this socket are able to get a list  
    # of all usernames and get results of everyone's userdb lookups.  

    unix_listener /var/spool/postfix/private/auth {  
            mode = 0666  
            user = postfix  
            group = postfix  
    }  

    unix_listener auth-userdb {  
            mode = 0600  
            user = vmail  
            #group =  
    }  

    # Postfix smtp-auth  
    #unix_listener /var/spool/postfix/private/auth {  
    #       mode = 0666  
    #}  

    # Auth process is run as this user.  
    user = dovecot  
}

找到文件中service auth-worker内容并修改如下:

service auth-worker {  
    # Auth worker process is run as root by default, so that it can access  
    # /etc/shadow. If this isn't necessary, the user should be changed to  
    # $default_internal_user.  

    user = vmail  
}

修改后文件如下

#default_process_limit = 100
#default_client_limit = 1000

# Default VSZ (virtual memory size) limit for service processes. This is mainly
# intended to catch and kill processes that leak memory before they eat up
# everything.
#default_vsz_limit = 256M

# Login user is internally used by login processes. This is the most untrusted
# user in Dovecot system. It shouldn't have access to anything at all.
#default_login_user = dovenull

# Internal user is used by unprivileged processes. It should be separate from
# login user, so that login processes can't disturb other processes.
#default_internal_user = dovecot

service imap-login {
  inet_listener imap {
    #port = 143
    port = 0 
  }
  inet_listener imaps {
    #port = 993
    #ssl = yes
  }

  # Number of connections to handle before starting a new process. Typically
  # the only useful values are 0 (unlimited) or 1. 1 is more secure, but 0
  # is faster. 
  #service_count = 1

  # Number of processes to always keep waiting for more connections.
  #process_min_avail = 0

  # If you set service_count=0, you probably need to grow this.
  #vsz_limit = $default_vsz_limit
}

service pop3-login {
  inet_listener pop3 {
    port = 0    
    #port = 110
  }
  inet_listener pop3s {
    #port = 995
    #ssl = yes
  }
}

service submission-login {
  inet_listener submission {
    #port = 587
  }
}

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
  #unix_listener lmtp {
    #mode = 0666
     mode = 0600  
     user = postfix 
     group = postfix 
  }

  # Create inet listener only if you can't use the above UNIX socket
  #inet_listener lmtp {
    # Avoid making LMTP visible for the entire internet
    #address =
    #port = 
  #}
}

service imap {
  # Most of the memory goes to mmap()ing files. You may need to increase this
  # limit if you have huge mailboxes.
  #vsz_limit = $default_vsz_limit

  # Max. number of IMAP processes (connections)
  #process_limit = 1024
}

service pop3 {
  # Max. number of POP3 processes (connections)
  #process_limit = 1024
}

service submission {
  # Max. number of SMTP Submission processes (connections)
  #process_limit = 1024
}

service auth {
  # auth_socket_path points to this userdb socket by default. It's typically
  # used by dovecot-lda, doveadm, possibly imap process, etc. Users that have
  # full permissions to this socket are able to get a list of all usernames and
  # get the results of everyone's userdb lookups.
  #
  # The default 0666 mode allows anyone to connect to the socket, but the
  # userdb lookups will succeed only if the userdb returns an "uid" field that
  # matches the caller process's UID. Also if caller's uid or gid matches the
  # socket's uid or gid the lookup succeeds. Anything else causes a failure.
  #
  # To give the caller full permissions to lookup all users, set the mode to
  # something else than 0666 and Dovecot lets the kernel enforce the
  # permissions (e.g. 0777 allows everyone full permissions).
  unix_listener auth-userdb {
    #mode = 0666
    #user = 
    #group = 
    mode = 0666
    user = vmail
  }

  # Postfix smtp-auth
  #unix_listener /var/spool/postfix/private/auth {
  #  mode = 0666
  #}

  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    user = postfix
  }


  # Auth process is run as this user.
  #user = $default_internal_user
  user= dovecot
}

service auth-worker {
  # Auth worker process is run as root by default, so that it can access
  # /etc/shadow. If this isn't necessary, the user should be changed to
  # $default_internal_user.
  #user = root
  user = vmail
}

service dict {
  # If dict proxy is used, mail processes should have access to its socket.
  # For example: mode=0660, group=vmail and global mail_access_groups=vmail
  unix_listener dict {
    #mode = 0600
    #user = 
    #group = 
  }
}

配置10-ssl.conf (ssl认证)

vim /etc/dovecot/conf.d/10-ssl.conf 
##
## SSL settings
##

# SSL/TLS support: yes, no, required. 
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
ssl = required

# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
#如果有证书可以改成自己的证书
ssl_cert = 

修改目录权限

# chown -R vmail:dovecot /etc/dovecot
# chmod -R o-rwx /etc/dovecot

重启dovecot和postfix

service dovecot restart 
service postfix restart

8、测试验证

使用本地客户端例如fixmail等


image.png

如果提示发件失败,那么我们可以查看一下日志
postfix日志在/var/log/mail.log

查看postfix和dovecot配置

postconf -n
dovecot -n
查看dovecot所有配置
dovecot -a

证书可以使用Let's Encrypt然后修改main.cf与10-ssl.conf 里文件的证书即可

smtpd_tls_key_file = /etc/letsencrypt/live/test.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/test.com/fullchain.pem

一个不错的邮箱测试工具

  • http://www.mail-tester.com/

image.png

你可能感兴趣的:(邮件服务器搭建)