Mailtrap and Testing
There are some problems you often encounter in Testing:
- You must test a system that has the function to send email to registered users. But these users are real users of the system. I guarantee, if you keep that test, your gods will receive junk mail like mushroom after rain, so annoying and violating security.
- Or less serious is that you have to send an email to a list of registered mail addresses, have your account, have someone else's account, how to confirm if not directly open all mailboxes that out?
You probably don't want that. So how to confirm the mail test without causing trouble to other users?
Mailtrap is a great solution for you.
Mailtrap provides a fake SMTP server (fake SMTP server) for the development team. Used to test emails sent from pre-production environments and test environments with real data, while avoiding the risk of sending email to real customers of the test system. It also allows you to automatically forward mail to your inbox regularly, share with your team and more!
Basically, you only need to register an account using Mailtrap, setting to synchronize with the project code of the app to test, and send all emails that need to be tested by the pre-production environment to email addresses that need to receive mail. notice ^^. All such emails will be sent to fake SMTP Mailtrap server instead of sent to the email you specified.
After that, you can view and check your emails in Mailtrap's friendly interface.
If your project is small, just need to test 1 user at a time and the number of emails to test is not too large, you can use Mailtrap for free. But for large projects, it is necessary to test with multiple users, corresponding to many different inboxes, in addition to the number of emails to test greater than 50 mail / inbox, the cost you need to pay to use Mailtrap will fluctuate in the range of from $ 120 to $ 300 per year depending on your needs.
I. Basic features of Mailtrap:
- Never happens to spam mail real customers because of development team negligence
- Analyze email for spam and blacklist
- HTML test for support by the common email clients
- Security default (HTTPS & TLS)
- Install quickly and easily using the config code
- Improve RESTful & POP3 API autotests
- Automatically forward emails to people who need them
- Arrange Email test in special mailbox
- Share inboxes with your team
II. How to get started with Mailtrap
1. Register an account:
You can easily register for a Mailtrap account with your existing email accounts, you can also use existing Google or Github accounts.
Here I use my Gmail account.
After successful registration and login, you can see Demo inbox in Mailtrap interface.
If you use a premium account, you can create more inboxes, each inbox will be corresponding to a different mailing system.
2. Configure Mailtrap:
Next, we will set up Mailtrap in your project development environment.
Open inbox, click on the "SMTP Settings" tab, you will see for each Mailtrap Inbox there will be information about the private SMTP server:
You can reset this information whenever you want.
Mailtrap provides a series of examples for configuration, which configuration options will depend on your project type. When there are multiple Inboxes, you can configure each Inbox with a project of different types.
For example: Configuring with Laravel project
For simplicity, we take the example of a small Laravel app that resets an account's password:
In the soucecode project of this app, open the environment configuration file and enter Mailtrap's SMTP server configuration parameters into the corresponding items.
Save the changes, and see the results!
After sending a password reset request to any email, normally the password reset email will be sent to the specified email address.
But when using Mailtrap, this email address will not receive the mail reset password notification, instead Mailtrap server will "catch" this mail and save in the inbox has been set. And we can check the content to reset the mail mail password in the inbox of Mailtrap.
In the body of the email you receive, there are a lot of tabs you can choose from, which allow you to check the content of the email received in many different formats:
By default, the email view is in HTML format. There is also a view in HTML source format:
Or Text, Raw:
You can also check the HTML of the email to check if it is correct by selecting the "Check HTML" tab, the result is an analysis of the HTML code lines that are being violated:
Finally, a tab that you cannot ignore – "Analysis" tab, provides you with analysis, reports on spam points and the blacklist of your messages and servers.
With such support, Mailtrap is an effective way to debug the content and markup of email messages you have sent.
3. Share inboxes and messages with your team
If your team has many other members who need to use the mailing function, and everyone needs to access your inbox to check the email sent? So there are 2 ways you can share your inbox:
- When your friend uses the free account:
There is no other way that you share your account with them, so they can access your mailbox on their device ^^.
- When they use premium account:
You can invite all developers (who have paid accounts) to access each mailbox via the link provided (this link will change when you click "Regenerate share link" link). Share steps are as follows:
- Step 1. Click "Company users" link on the Settings screen of the inbox you want to share.
Step 2. Send the generated system link to the user you want to invite.
You can also easily see the function of automatically forwarding all emails that Mailtrap receives to those who need it. However, this function is only available for paid accounts only ^^.
If you already have a paid Mailtrap account, and have used it effectively, don't forget to share it with me and everyone else.
Conclusion: If you are a Tester, you are not allowed to "touch" sourcecode. So you can't configure it now, how to test mail sending with Mailtrap? Simple, please ask your dev to configure it on your device, then ask for your Mailtrap account (that's in case you use a free account) or ask him to share inbox for (in case You use a genuine account: P), go back to your computer, log in to Mailtrap, that's it! Then, you can freely test the mail sending function of the system, but no longer afraid that the spam mail you create affects the real users of the system.
Reference articles from links: https://code.tutsplus.com/tutorials/introduction-to-mailtrap-a-fake-smtp-server-for-pre-production-testing–cms-23279