I’m having trouble with my Mailgun setup and emails aren’t being delivered when I send to addresses that use the same domain as my Mailgun configuration. Everything works fine when sending to different domains though.
For instance, if my Mailgun domain is set to example.org, sending emails to [email protected] fails to deliver. The Mailgun dashboard shows the messages as accepted but they never reach the inbox.
I suspect this might be a configuration problem rather than a coding issue. Here’s my implementation:
const mailgunClient = require('mailgun-js')({
apiKey: process.env.MG_API_KEY,
domain: process.env.MG_DOMAIN,
host: process.env.MG_HOST
})
const emailData = {
from: '[email protected]',
to: '[email protected]',
subject: 'Test Message',
text: 'Hello world'
}
mailgunClient.messages().send(emailData, (err, response) => {
if (err) {
console.error('Send failed:', err)
return
}
console.log('Email sent:', response)
})
My DNS configuration looks correct to me:
MX Records:
- Host: example.org | Priority: 10 | Value: mxa.eu.mailgun.org
- Host: example.org | Priority: 10 | Value: mxb.eu.mailgun.org
I’ve also added the required TXT records for verification.
No errors appear in my application logs. Any suggestions on what might be causing this same-domain delivery issue?