Videos
Check out our tutorial video series.
Test mailserver responses using bounce simulation rules in MailSlurp
Email bounces and rejections are common in email delivery. They can occur for various reasons, such as invalid email addresses, full mailboxes, or server issues. In this guide, we will explore how to simulate soft and hard bounces using MailSlurp's bounce simulation rules.
Email bounces occur when an email cannot be delivered to the recipient's mailbox. There are two main types of bounces:
Soft Bounce: This is a temporary issue, such as a full mailbox or a server that is temporarily unavailable. The email may be delivered later. A soft bounce typically results in a SMTP error code.
Hard Bounce: This is a permanent issue, such as an invalid email address or a domain that does not exist. A hard bounce typically results in a SMTP error code.
Simulating bounces is useful for testing email delivery and bounce handling in your application. It allows you to verify that your application can handle bounce scenarios correctly without sending real emails to invalid addresses.
In MailSlurp, you can simulate bounces by creating a ruleset with a bounce action. This ruleset can be applied to an inbox to simulate soft and hard bounces for incoming emails.
To simulate bounces, you need to create an SMTP inbox. This type of inbox uses a custom MX server that can return and
SMTP error codes for soft and hard bounces, respectively. Using the MailSlurp API or Javascript client, you can create an SMTP inbox like this:
Next we need to attach a rule to the inbox that will cause it to return a bounce response. This can be done by creating a ruleset with a bounce action for receiving emails. The ruleset can be created in code like so:
Now that we have an inbox with a ruleset we can test the bounce. To do so we need to get the smtp server details for the inbox like so:
Then we can use an SMTP client (like ) to send an email to the inbox and observe the bounce response. Here is an example of a hard bounce test using the
library:
That's it! You have successfully simulated soft and hard bounces using MailSlurp's bounce simulation rules. This allows you to test your application's email handling capabilities without sending real emails to invalid addresses. You can now handle bounce scenarios effectively in your application.
This bounce simulator works with any SMTP client or mail provider. For more information, see the inbox rulesets documentation and the InboxRulesetController.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.