Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器

网站所有资源都有,可联系VX:bjlyxy1688

Postfix负责SMTP服务,Dovecot负责IMAP服务,Roundcube是一个WEBMail客户端,如果不需要这个可以不装。

这应该是Postfix+Dovecot的最简配置,没有配置虚拟用户,没有任何防病毒/SPAM配置,512MB内存的小鸡都可以运行的。

我个人的需求是自用,所以用不到虚拟用户,防病毒这个也用不到。SPAM还是有必要的,后续打算用Rspamd,等配置好了再水一篇文章。。

开始之前你需要先准备一个域名,添加一下解析记录。

A记录到你的服务器IP:

图片[1]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

MX记录:

图片[2]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

再设置2个CNAME记录(可选)SMTP别名:

图片[3]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

IMAP别名:

图片[4]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

以下步骤仅在Debian10上测试通过,且务必保证你的系统是“干净”的,没有安装其他乱七八糟的软件。

首先安装一些基本工具以及Nginx/Mariadb/PHP(如果不需要Roundcube可以不装这些):

apt -y update
apt -y install wget curl gnupg
apt -y install nginx python-certbot-nginx mariadb-server
apt -y install php7.3-common php7.3-fpm php7.3-imap php7.3-mysql php7.3-mbstring php7.3-xml php7.3-intl php7.3-zip php7.3-gd php7.3-ldap

安装Postfix/Dovecot,Debian10官方存储库内的Dovecot版本太旧,这里添加官方的源安装新版:

curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import
gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg
echo "deb https://repo.dovecot.org/ce-2.3-latest/debian/buster buster main" > /etc/apt/sources.list.d/dovecot.list
apt -y update
apt -y install postfix dovecot-core dovecot-imapd

安装Postfix的时候会提示让你选择什么用途,选择如下图所示的选项:

图片[5]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

然后填上你的域名,域名直接填写根域名,不要带什么http/www这些:

图片[6]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

修改Postfix的配置,这里用postconf这个工具执行下面的命令就行:

postconf -e "home_mailbox = Maildir/"
postconf -e "smtpd_sasl_auth_enable = yes"
postconf -e "smtpd_sasl_type = dovecot"
postconf -e "smtpd_sasl_path = private/auth"
postconf -e "smtpd_sasl_security_options = noanonymous"
postconf -e "smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"
postconf -n

重启postfix:

systemctl restart postfix

接下来编辑Dovecot的验证配置文件:

nano /etc/dovecot/conf.d/10-auth.conf

修改下面两项配置:

disable_plaintext_auth = no
auth_mechanisms = plain login

修改Dovecot存储邮件的路径:

nano /etc/dovecot/conf.d/10-mail.conf

替换成下面的配置即可:

mail_location = maildir:~/Maildir

接着建立Dovecot与Postfix的验证方式:

nano /etc/dovecot/conf.d/10-master.conf

修改为如下配置:

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

重启Dovecot:

systemctl restart dovecot

设置Postfix/Dovecot/Nginx/Mariadb/PHP-FPM开机自启:

systemctl enable postfix dovecot nginx mariadb php7.3-fpm

创建邮箱账号并修改密码,因为是用于登录邮箱的账户,不要给它登录SSH的权限:

useradd -m -s /sbin/nologin imlala
passwd imlala

至此一个SMTP和IMAP服务就搭建好了,你可以使用其他客户端连接上你的服务器收发邮件啦,为方便使用这里再安装一个Roundcube。

初始化Mariadb/登录到Mariadb内:

mysql_secure_installation
mysql -u root -p

创建数据库/用户/授权:

CREATE DATABASE roundcube CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost IDENTIFIED BY '设置你的数据库用户密码';
FLUSH PRIVILEGES;

下载Roundcube源码/解压/给予正确的权限:

cd /var/www
wget https://github.com/roundcube/roundcubemail/releases/download/1.4.3/roundcubemail-1.4.3-complete.tar.gz
tar -xzvf roundcubemail-1.4.3-complete.tar.gz
rm -rf roundcubemail-1.4.3-complete.tar.gz
mv roundcubemail-1.4.3 roundcubemail
chown -R www-data:www-data roundcubemail/

导入Roundcube的初始数据:

mysql roundcube < roundcubemail/SQL/mysql.initial.sql

新建一个Nginx配置文件:

nano /etc/nginx/conf.d/roundcube.conf

写入如下配置:

server {
    listen       80;
    server_name  mail.233.fi; # 换成你的域名
    index        index.html index.php;
    root         /var/www/roundcubemail;
    client_max_body_size 128G;

    error_log /var/log/nginx/roundcube.error.log;
    access_log /var/log/nginx/roundcube.access.log;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }

    location ~ ^/(bin|SQL)/ {
        deny all;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.3-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

测试Nginx配置:

nginx -t

没问题的话使用CertBot签发一个SSL证书:

certbot --nginx --agree-tos --no-eff-email --email xxxxx@qq.com

打开你的域名开始安装:https://mail.233.fi/installer/

这里就是填写一些MySQL的数据库连接信息,然后SMTP/IMAP连接信息,其他的根据自己的需要看要不要装一些插件什么的,自己看着配置就行了。

安装完成之后你将看到Roundcube的登录界面:

图片[7]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

使用你之前用useradd命令创建的账号登录即可,账号不需要加@登录,直接用你创建的用户名登录就行。

登录进去之后你可能需要更改一下发件人的邮件地址,这里可能默认显示imlala@localhost,你要把它改成自己的域名:

图片[8]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

最后测试一下能否正常使用,先发个信看看:

图片[9]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

看看能收不:

图片[10]-Debian10使用Postfix+Dovecot+Roundcube搭建邮件服务器-天时网

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
The greatest test of courage on earth is to bear defeat without losing heart.
世界上对勇气的最大考验是忍受失败而不丧失信心
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容