大网数据广告活动
服务器运维问答

Use CNAME for SMTP Server

· 52CE 我爱测

I am working on a project that involves use of a transactional email service (like sendgrid). My question is can we create a CNAME in our domain DNS (i.e. smtp.example.com or client1.example.com) that refers to the email service …

问题原文

原帖链接 · vbuser2004 · CC BY-SA 3.0

I am working on a project that involves use of a transactional email service (like sendgrid). My question is can we create a CNAME in our domain DNS (i.e. smtp.example.com or client1.example.com) that refers to the email service smtp server?

This will mask the SMTP server of the service (i.e. sendgrid, mailgun) we use.

Our goal is to vary the DNS entry depending on our client. As an example, we might have client1.example.com, client2.example.com, etc. Each client subdomain would be a CNAME to the email service. We could also switch email services just by changing where the CNAME refers if needed. As an example:

    NAME                    TYPE   VALUE
--------------------------------------------------
client1.example.com        CNAME  smtp.emailservice.com
client2.example.com        CNAME  smtp.emailservice.com

In doing research on this it appears to work, but I wanted to see if there were any issues that I should look for. We are not dealing with MX records, POP3, or any incoming emails at all, nor can we use an API for sending. It has to go through SMTP.

Thank you!

已采纳解答

原帖链接 · the-wabbit · CC BY-SA 4.0

The naive answer to your question is a simple "yes". You obviously can create CNAME RRs in the suggested fashion. Which problems may arise thereof, is an entirely different matter - CNAMES are commonly misunderstood and the usage is prone to errors.

Main points to consider are:

  • you must not use your CNAMEs as destinations for MX RRs (RFC 2181 section 10.3)
  • you must not create any other RR type definitions for the labels you are defining as CNAMEs (STD 13, RFC 1034, section 3.6.2)

So, taking the RR definitions from your question as a prerequisite, the following cases would present invalid use:

; these are INVALID RR definitions, don't even try!
mail.example.com.     IN MX  client1.mydomain.com. ; no MX to CNAME RRs
client1.mydomain.com. IN A   198.51.100.203        ; no other RR types for CNAMEd labels

In future posts, when using IP addresses and name spaces for example and / or documentation purposes, consider sticking to the definitions of IPv4 Address Blocks reserved for Documentation (RFC 5737) and Special-Use Domain Names (RFC 6761) to avoid confusion.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。