Skip to content

Handle domain rejects email #3

@bryan-gilbert

Description

@bryan-gilbert

If client provides an email address that is not accepted by the domains MTA then be sure to have the API return a fail message rather than a success message.

sendMailMiddleware mailQuery {
  toAddress: 'sample@example.com',
  subject: 'Verification code',
  htmlBody: '<html lang="en"><head></head>\n' +
    '  <body>\n' +
    '    <p>verification code 35155    </p></body></html>',
  textBody: 'verification code 35155'
}
sendMailMiddleware sendmail
UNEXPECTED ERROR Error: Can't send mail - all recipients were rejected: 556 5.1.10 <sample@example.com>: Recipient address rejected: Domain example.com does not accept mail (nullMX)
    at SMTPConnection._formatError (/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
    at SMTPConnection._actionRCPT (/node_modules/nodemailer/lib/smtp-connection/index.js:1613:28)
    at SMTPConnection.<anonymous> (/node_modules/nodemailer/lib/smtp-connection/index.js:1566:30)
    at SMTPConnection._processResponse (/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
    at SMTPConnection._onData (/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
    at Socket.SMTPConnection._onSocketData (/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:284:9)
    at Socket.Readable.push (_stream_readable.js:223:10) {
  code: 'EENVELOPE',
  response: '556 5.1.10 <sample@example.com>: Recipient address rejected: Domain example.com does not accept mail (nullMX)',
  responseCode: 556,
  command: 'RCPT TO',
  rejected: [ 'sample@example.com' ],
  rejectedErrors: [
    Error: Recipient command failed: 556 5.1.10 <sample@example.com>: Recipient address rejected: Domain example.com does not accept mail (nullMX)
        at SMTPConnection._formatError (/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
        at SMTPConnection._actionRCPT (/node_modules/nodemailer/lib/smtp-connection/index.js:1599:24)
        at SMTPConnection.<anonymous> (/node_modules/nodemailer/lib/smtp-connection/index.js:1566:30)
        at SMTPConnection._processResponse (/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
        at SMTPConnection._onData (/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
        at Socket.SMTPConnection._onSocketData (/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
        at Socket.emit (events.js:315:20)
        at addChunk (_stream_readable.js:309:12)
        at readableAddChunk (_stream_readable.js:284:9)
        at Socket.Readable.push (_stream_readable.js:223:10) {
      code: 'EENVELOPE',
      response: '556 5.1.10 <sample@example.com>: Recipient address rejected: Domain example.com does not accept mail (nullMX)',
      responseCode: 556,
      command: 'RCPT TO',
      recipient: 'sample@example.com'
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions