I'm trying to send an email on behalf of my user using nodemailer but all my emails are being rejected.
My transporter works for normal use-cases where I'm sending from my own domain:
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>",
})
But when I try to send on behalf of my user it doesn't work:
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"
I figured if I set a DKIM DNS record and an SPF record on exampleshop.com it would mean I could send emails on behalf of the domain but still no luck.
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>
It's also been over an hour since I've updated the DNS records, I'm not sure what I'm doing wrong here.