Email verification
How to verify email addresses to ensure delivery.
Quick links
About email validation
Email verification can be used to check whether an email address is valid or exists. Use verification to prevent bounced emails and maintain a clean email list. There are several ways to use verification:
Verify during sending
The simplest way to verify is to pass a validateEmailAddresses
option when sending mail:
// the `validateEmailAddresses` option will verify then filter and remove bad recipients
// you can also configure the method to throw instead with `VALIDATE_ERROR_IF_INVALID`
await mailslurp.sendEmail(inboxId, {
to: [recipient, bouncedRecipient],
validateEmailAddresses:
SendEmailOptionsValidateEmailAddressesEnum.VALIDATE_FILTER_REMOVE_INVALID,
});
This will validate the email addresses before sending. If any are invalid the send will filter out failing recipients.
Clean email lists
Another validation method is to check emails in at the time of email address collection.
const mailslurp = new MailSlurp(config);
const res =
await mailslurp.emailVerificationController.validateEmailAddressList({
validateEmailAddressListOptions: {
emailAddressList: ['contact@mailslurp.dev', 'bad@mailslurp.dev'],
},
});
expect(res.resultMapEmailAddressIsValid['contact@mailslurp.dev']).toEqual(
true
);
expect(res.resultMapEmailAddressIsValid['bad@mailslurp.dev']).toEqual(
false
);