惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
月光博客
月光博客
腾讯CDC
Engineering at Meta
Engineering at Meta
博客园 - Franky
Vercel News
Vercel News
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
GbyAI
GbyAI
B
Blog
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog

Dallas Lu

一些没有意义的事情 博客程序的一次大重构 OpenWRT 使用 udp2raw 对抗 WireGuard 阻断 如何证明你是原创作者 Nginx 泛域名配置的隐患与对策 WISeID S/MIME 证书 V2EX 刑满释放记 使用 Radicale 在 Ubuntu 24.04 中搭建 vCards CardDav 服务 邮件服务的域名成功从 SURBL 黑名单移除 The Domain of Mail successfully removed from SURBL blacklist 网站多语言的设计细节 Website Multilingual Design Details 网站评论系统的目前进展和展望 Current Progress and Outlook of the Website Comment System 在公网使用 iptables 转发端口时保留客户端 IP Retaining Client IP with iptables Port Forwarding on Public Networks 邮件投递平台 Postal 的使用经验 自建 Postal 完美替代 SendGrid Build Your Own SendGrid: Postal SMTP Server 互联网在崩塌吗,然后呢 Is the Internet collapsing and then what 在 SvelteKit 应用中使用 JSON-LD Using JSON-LD in SvelteKit Applications 网页的打印样式应该怎么写 How to write print styles for web pages “茴字的四种写法”之 IP 与域名 Trivia: Special ways of writing IP and domain names 怎么伪造 Git 提交的时区 How to fake the timezone of a git commit 供大众交流的论坛和其它替代产品还是不好用
Experience with Using Postal, the Mail Delivery Platform
Dallas Lu · 2024-07-09 · via Dallas Lu

I have been using Postal as a replacement for SendGrid for some time now. It can almost completely replace SendGrid. During its use, I encountered some issues. This article records some experiences.

Issues with Port 25 for SMTP Client

When a server sends an email, it first checks the domain part of the email address, queries the MX records, finds the mail server for that email, and delivers the message. In the default process, it needs to connect to port 25. If a server is restricted from connecting to port 25 of other servers, it cannot easily send emails. Many VPS providers restrict outbound traffic to port 25 for this reason.

Postal only provides an SMTP port, which is 25. Although it can use the HTTP interface to send emails, most applications do not adapt to its HTTP interface, making SMTP the most common solution. If you encounter such a VPS, you will have to find another way.

One way is to use a Socks proxy to route the outbound traffic of port 25 through a different path to bypass the restriction. However, the proxy server may also restrict port 25.

Another method is to enable an alternative port on the Postal SMTP server, such as 2525. However, Postal itself only allows setting one port. You can use iptables on the Postal server to provide alternative ports:

iptables -t nat -A PREROUTING -p tcp --match multiport --dports 587,2525 -j REDIRECT --to-ports 25

Separate Domain for SMTP Service

As mentioned above, Postal exposes only two services externally:

  • Web service providing the management panel and HTTP API
  • SMTP service for sending and receiving emails

They share the domain postal.example.com. This means you cannot use Cloudflare’s proxy feature to speed up Postal’s web service. So, we need to split the domains for the two services.

Fortunately, Postal supports this configuration. We can edit the configuration file /opt/postal/config/postal.yml, set smtp_hostname to smtp.example.com, and configure the DNS A record and corresponding IP PTR record.

PTR Records of Postal Server

Many VPS providers offer an online interface to modify PTR records, while some require submitting a ticket. Generally, it’s recommended to keep the hostname and PTR record consistent. During SMTP server negotiation of STARTTLS, the hostname declared in the banner will be verified against the PTR record. If helo_hostname is not configured in Postal, it will use the value of smtp_hostname as the hostname.

In the mail protocol, there is no mandatory standard for client verification of the certificate. The client may or may not verify the domain name, and even self-signed certificates can be used. Some clients require the SMTP server’s declared hostname to match, while others may require it to match the MX record domain or the connecting domain (like the Bamboo library used by Plausible).

PTR records are not directly related to TLS, but there is a subtle connection through helo_hostname. In Postal and Mail-in-a-box by default, only one domain is used, so no issues arise.

However, in some special cases, when your Postal has multiple backup IPs or an IP pool, some IPs might only be used for outbound traffic and not provide web or receiving services. The default smtp_hostname may not match the PTR records of these outbound-only IPs.

Unfortunately, there is an issue with the current implementation of helo_hostname, making it ineffective. So, my current solution is to first modify the smtp_hostname in the configuration file to helo.example.com, restart the SMTP service (docker restart postal-smtp-1), then change smtp_hostname back to smtp.example.com, and restart the web service (postal-web-1). This way, multiple A records for helo.example.com can point to each outbound IP to pass the PTR check.

Certificate Issues

Postal supports STARTTLS on port 25. We just need to enable tls with smtp_server.tls_enabled: true in Postal’s configuration file and add the key and certificate to the default paths:

  • /opt/postal/config/smtp.key
  • /opt/postal/config/smtp.cert

Given the lack of standards for client verification logic of SMTP certificates, it is best to use a multi-domain certificate that includes the domains used in the mail system or use a WildCard certificate.

Conclusion

I had to find an alternative due to an issue with my SendGrid account; shortly after, another well-known product by its developer Twilio, Authy, experienced a phone number leakage incident. I recommend everyone who has used SendGrid to look for a good alternative, and self-hosting Postal is a very worthwhile solution to try.