准备工作
DNS服务器
在域名的DNS管理页添加如下记录
Type |
Name |
Value |
A |
mail |
xxx.xxx.xxx.xxx |
MX |
@ |
mail.xxx.com |
公网服务器防火墙
首先查看防火墙端口状态
然后开放如下端口
名称 |
协议 |
端口号 |
SMTP |
TCP |
25 |
IMAP |
TCP |
143 |
POP3 |
TCP |
110 |
SMTP-SSL |
TCP |
465 |
SMTP-TLS |
TCP |
587 |
通过 SSL/TLS 的 IMAP |
TCP |
993 |
通过 SSL/TLS 的 POP3 |
TCP |
995 |
frp
在公网服务器frps的配置文件frps.ini
添加
1 2
| [common] subdomain_host = xxx.com
|
在家里的软路由frpc内添加添加对应的远程端口和TCP协议
内容与上面的防火墙设置一样
此外添加二级域名的代理
1 2 3 4
| [mail] type = http local_port = 80 subdomain = mail
|
Nginx
邮件的Web客户端也需要用80端口,但由于公网服务器上Nginx已经占用了80端口
所以我们修改Nginx配置,在二级域名mail上让nginx转发80流量到frp的8080端口
添加frp.conf
,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| server { listen 80; server_name mail.xxx.com;
location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_hide_header X-Powered-By; } } server { listen 443 ssl; server_name mail.xxx.com;
# ssl on; ssl_certificate /etc/letsencrypt/live/mail.xxx.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mail.xxx.com/privkey.pem; ssl_prefer_server_ciphers on; ssl_session_timeout 60m;
location / { proxy_pass http://127.0.0.1:8081; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_hide_header X-Powered-By; } }
|
邮件服务器安装
群晖套件中心安装Mail Server
启用SMTP,填写主机名xxx.com
启用SMTP-SSL,启用SMTP-TLS
测试使用
群晖套件中心安装Mail Station
访问地址为http://mail.xxx.com/mail
使用其他邮箱互发邮件
It Works!
使用群晖MailPlus套件
此软件免费授权只有5个帐号
胜在Web端UI精致,还有APP供选择
改用此套件,服务器端设置基本相同
需要注意的是
DSM设置
Web客户端访问地址需要打开
在控制面板
中打开应用程序门户
选择MailPlus
,启用自定义别名mail
,就可以通过如下地址直接访问
https://xxx.xxx.xxx.xxx/mail
frpc修改
修改二级域名mail的参数
1 2 3 4
| [mail] type = http local_port = 5000 subdomain = mail
|
Nginx
将mail.xxx.com
的地址重定向到mail.xxx.com/mail
便于访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| server {
listen 80; server_name mail.hack42.com;
location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_hide_header X-Powered-By; }
} server { listen 443 ssl; server_name mail.hack42.com;
if ($host = 'mail.hack42.com' ) { rewrite ^/(.*)$ http://mail.hack42.com/mail; } # ssl on; ssl_certificate /etc/letsencrypt/live/mail.hack42.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/mail.hack42.com/privkey.pem; # managed by Certbot ssl_prefer_server_ciphers on; ssl_session_timeout 60m;
location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_hide_header X-Powered-By; } }
|
此外,记得签发二级域名的证书
访问地址为http://mail.xxx.com/
It Works!