When building an app you often need to run through parts of the system manually to check how functionality works or checking a bug report.
A lot of the time this will require creating a new user account on the system, following the steps that a normal user would need to follow.
Most online accounts require a unique email address. This constraint leaves demo systems full of email addresses like
firstname.lastname@example.org. Let’s talk about a great way to generate test email addresses.
The problems with example.com
Using fake email addresses hides issues when your development environment sends the email out.
- You don’t get to see if the email actually shows in an email client
- If you use a fake domain and that domain starts being used by someone you could end up sending test emails to a real person
- When you need to follow a link in an email, for example password resets, you have to look through logs
Using a real email address
Using a real email address bypasses these issues. It has the downside of being a finite resource. We don’t have access to thousands of easy to manage email addresses.
Gmail has this wonderful feature to create unique email addresses that link to your main email.
If your main account was
email@example.com then you can create append
+tag before the
These are all valid email addresses that will all go into the same inbox:
We can use one real account to generate lots of unique emails for our demo systems.
Generating unique email addresses by hand doesn’t scale. This is where TextExpander comes in.
You can use TextExpander to add a custom
+ to your email address.
There are a few ways we can generate something random.
TextExpander lets you instantly insert “snippets” of text as you type – using a quick search or abbreviation. So, we’ll make a “snippet” to help us make new email addresses very quickly.
By writing a snippet that makes use of the bash variable
RANDOM we can generate an email address that will be random enough for our purposes.
- Open the TextExpander app and create a new snippet
- Set the Content type to Shell Script
- Paste the following as the body of your snippet
#!/bin/bash echo -n "pixel+$RANDOM@gmail.com"
This will generate:
For a longer post on bash commands you will enjoy How to Instantly Insert Your Most Used Bash Commands.
You can also use date based emails, this will be unique and also let you see at a glance when you created it.
pixel+(Year: 2001)(Month: 01)(Day: 01)(Hour: 01 (00-23))(Minute: 01)(Second: 01)@gmail.com
This will generate:
Using Gmail and TextExpander, never run into the email problem again when testing the signup flow of your system.
If you’d like to play with the snippets in this post, you can check out our sample bash scripts Public Group.