首页 > 解决方案 > 使用 nodemailer 代表某人发送电子邮件

问题描述

我正在尝试代表我的用户发送一封电子邮件,nodemailer但我的所有电子邮件都被拒绝了。

我的传输器适用于我从自己的域发送的正常用例:

const transporter = nodemailer.createTransport({
    host: 'emailhost.com',
    port: 465,
    secure: true, 
    auth: {...},
    dkim: {
      domainName: <domainname>,
      keySelector: <keyselector>,
      privateKey: <privatekey>,
    },
  });

transporter.sendMail({
  subject: "Shop subject",
  from: `kyle@mydomain.com`,
  to: <customerEmail>,
  replyTo: <shopEmail>,
  html: "<div>my user message</div>",
})

但是当我尝试代表我的用户发送时它不起作用:

transporter.sendMail({
  subject: "Shop subject",
  from: `shop@exampleshop.com`,
  to: <customerEmail>,
  // sender: `kyle@mydomain.com` <-- Also tried adding this field,
  replyTo: `shop@exampleshop.com`,
  html: "<div>my user message</div>",
})

>> "Can't send mail - all recipients were rejected: 553 <shop@exampleshop.com>: Sender address rejected: not owned by user kyle@mydomain.com"

我想如果我在其上设置 DKIM DNS 记录和 SPF 记录,exampleshop.com则意味着我可以代表域发送电子邮件,但仍然没有运气。

Type: TXT Record 
Host: @ 
Value: v=spf1 include:spf.emailhost.com ~all

// Also tried adding this record in place of the one above
Type: TXT Record 
Host: @ 
Value: v=spf1 include:spf.mydomain.com ~all

Type: TXT Record 
Host: default._domainkey
Value: v=DKIM1;k=rsa;p=<DKIM DNS record from namecheap>

自从我更新 DNS 记录以来也已经一个多小时了,我不确定我在这里做错了什么。

标签: javascriptemailnodemailerspfdkim

解决方案


推荐阅读