如何从根域发送和接收mailgun中的电子邮件(为子域配置)

sol*_*ant 15 dns mailgun

Mailgun建议为子域创建DNS(TXT,MX,..)记录,但是稍后配置可以通过根域发送和接收状态.我在我的注册商和Mailgun(添加域名,设置路由等)中为mail.example.com创建了所有必要的步骤.我现在可以收到并发送电子邮件到配置的example@mail.example.com.

我现在需要更改什么才能在example@example.com上发送和接收?注册商,邮件枪和gmail的smtp设置(通过mailgun从gmail发送)有哪些必要的更改?

非常感谢你!

Ant*_*rov 17

如果为子域配置Mailgun,则可以通过适当的to变量从主域发送电子邮件.例如,使用Node.js + nodemailer+ nodemailer-mailgun-transport:

var nodemailer = require('nodemailer'),
    mg = require('nodemailer-mailgun-transport'),
    auth = { api_key: 'foobar', domain: 'mail.example.com' },
    nodemailerMailgun = nodemailer.createTransport(mg({ auth: auth }));

nodemailerMailgun.sendMail({
    from: 'helloworld@example.com',
    to: 'recipient@domain.com',
    subject: 'Hey you, awesome!',
    text: 'Mailgun rocks, pow pow!'
}, someCallback);
Run Code Online (Sandbox Code Playgroud)

或者您可以阅读其他文档中通过API发送的方法.无论如何,即使您的Mailgun配置为子域,您也可以从主域发送电子邮件.

但是(!)您的MX记录是针对您的子域配置的,因此您只能在那里接收电子邮件.为了能够接收到您的主域的电子邮件,请在Mailgun的控制面板中添加您的主域名,例如mail.example.com,但是example.com,并在您的DNS控制面板中为此主域进行相应配置,为DigitalOcean的DNS example.com(非子域)配置示例:

TXT    @                v=spf1 include:mailgun.org ~all
TXT    krs._domainkey   k=rsa; p=MIGfM...blablabla
CNAME  email            mailgun.org.
MX     10               mxa.mailgun.org.
MX     10               mxb.mailgun.org.
Run Code Online (Sandbox Code Playgroud)

请记住,如果您有适当的规则集,Mailgun没有邮箱功能,它只能转发传入的电子邮件.大多数人将其主域名的MX记录委托给更易管理的ESP,如Gmail.您只能为域提供一组MX记录,因此您必须选择Gmail或Mailgun.