Testing email templates, whether for existing features or new features, is a common task performed by testers during the testing process. There are many ways to manage sending emails on different environments:
– Development
– Testing
– Staging
– Production
You have to consider how your application should behave in all of these environments.
How companies deal with this problem?
First, and in my opinion, the worst case scenario occurs when the development team decides to add special logic to their EmailService, redirecting all emails to a specific email address, or when we allow sending emails to workers within our organization.
It shouldn’t pass code review.
This is the worst possible option for resolving this problem. This code cannot be tested to ensure that the application works correctly at the current time.
In this code, we have separated the logic for each environment, so there is no need for conditional statements (‘if’ statements) in the implementation types.
However, this version is also not as good as it could be.
Emails used for testing purposes should not be sent outside of the organization’s infrastructure.
So let’s go further.
What should we do to make this code look nice?
First of all, in the perfect case we have no ‘if’ statements in our code. It’s possible to do with several ways. I’ll talk here about 2 different ways to achieve this goal but without code.
What should it look like?
We should only change credentials stored in .NET web applications’ appsettings.jsonfiles. Different environment credentials should be stored in different files. In the best-case scenario, only the developer’s credentials should be stored directly, while all other credentials should be stored in either dotnet secrets or Azure Key Vault
1. Create Fake SMTP Server
It’s a good option when we want to keep everything within our private infrastructure, which is very important for large organizations.
For development purposes, we have credentials for a Fake SMTP Server, and the code itself does not change.
How should work Fake SMTP Server?
The Fake SMTP Server should receive the same data as a real SMTP Server as input, but instead of sending it, it should save the data to a database. Additionally, it should provide a public interface (for example, a web frontend) to search for emails.
2. Use Fake SMTP Server as a Service
INFORMATION
I would like to emphasize that I don't have a partnership with any company and the indication of a specific service is only because I had the opportunity to use it in commercial project.
Mailtrap is an easy-to-use platform for sending real and test emails from our applications. I’ve only tested the Email Testing feature, so I’ll mainly focus on it.
Mailtrap offers a clear web interface to read all sent emails.
What makes this product stand out?
Testers can view all emails sent from the application. When they analyze test cases that have been tested by others, they can also verify emails.
How to test email sending service?
Testing email templates, whether for existing features or new features, is a common task performed by testers during the testing process. There are many ways to manage sending emails on different environments:
You have to consider how your application should behave in all of these environments.
How companies deal with this problem?
First, and in my opinion, the worst case scenario occurs when the development team decides to add special logic to their EmailService, redirecting all emails to a specific email address, or when we allow sending emails to workers within our organization.
It shouldn’t pass code review.
This is the worst possible option for resolving this problem. This code cannot be tested to ensure that the application works correctly at the current time.
In this code, we have separated the logic for each environment, so there is no need for conditional statements (‘if’ statements) in the implementation types.
However, this version is also not as good as it could be.
Emails used for testing purposes should not be sent outside of the organization’s infrastructure.
So let’s go further.
What should we do to make this code look nice?
First of all, in the perfect case we have no ‘if’ statements in our code. It’s possible to do with several ways. I’ll talk here about 2 different ways to achieve this goal but without code.
What should it look like?
We should only change credentials stored in .NET web applications’ appsettings.json files. Different environment credentials should be stored in different files. In the best-case scenario, only the developer’s credentials should be stored directly, while all other credentials should be stored in either dotnet secrets or Azure Key Vault
1. Create Fake SMTP Server
It’s a good option when we want to keep everything within our private infrastructure, which is very important for large organizations.
For development purposes, we have credentials for a Fake SMTP Server, and the code itself does not change.
How should work Fake SMTP Server?
The Fake SMTP Server should receive the same data as a real SMTP Server as input, but instead of sending it, it should save the data to a database. Additionally, it should provide a public interface (for example, a web frontend) to search for emails.
2. Use Fake SMTP Server as a Service
INFORMATION
I would like to emphasize that I don't have a partnership with any company and the indication of a specific service is only because I had the opportunity to use it in commercial project.
Mailtrap is an easy-to-use platform for sending real and test emails from our applications. I’ve only tested the Email Testing feature, so I’ll mainly focus on it.
Mailtrap offers a clear web interface to read all sent emails.
What makes this product stand out?
Testers can view all emails sent from the application. When they analyze test cases that have been tested by others, they can also verify emails.
Archives
Understanding K-Nearest-Neighbors (KNN) – Essential Machine Learning Algorithm
2024-10-06A Step-by-Step Guide to Web Scraping for Beginners
2024-07-12Categories
Meta