17

I have to add new users in a web application. Users need valid email addresses and users are activated by clicking activation link sent to their emails. As I have to add dozens of users so I cannot add so many email addresses. I know websites like yopmail that it generates email address but it is not safe and anyone can access those email links. I need a safe email address so that no one else can access them.

  • 1
    Just to add to @user246's answer - Gmail is a much better choice than Hotmail or Outlook for this. A previous employer tried the same approach with Microsoft's email clients and quickly found that they were blacklisted for spam emails (to be fair, they were sending 1000's a day). I've not yet heard of Gmail blacklisting senders. – trashpanda Feb 8 '18 at 11:02
25

Here is one approach. If you have a Gmail account with an address of, say, abdullah@gmail.com, I can send emails to you at abdullah+ARBITRARY-STRING@gmail.com.

Each of your users can have a different Gmail address, e.g. abdullah+1@gmail.com, abdullah+2@gmail.com, and adbdullah+3@gmail.com, but they will all correspond to the same Gmail account.

  • 2
    Awesome trick! Good to know. +1 Hopefully email validator would allow the PLUS sign. – Peter M. - stands for Monica Feb 7 '18 at 17:38
  • 6
    It also verifies that your application properly supports email+identifier@example.com style addresses. I could see some aggressive but incorrect email "validator" stopping such things. – corsiKa Feb 7 '18 at 18:02
  • 6
    Using real smtp (or any real messaging infrastructure) is not a very good practice. You're always at risk of making your test data leak to the real people. – Alexey R. Feb 7 '18 at 20:31
  • 6
    I agree that it's a risk, but not testing your email logic is a risk too. And this Gmail trick is available to QA teams who are not in the position to deploy their own SMTP server, reconfigure DNS records, or reconfigure applications. You could argue that QA teams should be able to do all this things, but the reality is that they are often left at the mercy of unsympathetic sysadmins. – user246 Feb 7 '18 at 21:50
  • 2
    @PeterMasiar Unfortunately, far too many people feel the need to write their own (shitty) e-mail verification regexes, even though RFC 5322 standardizes it. – Alexander - Reinstate Monica Feb 8 '18 at 2:50
17

Deploy test SMTP server in your local network where the application does have access to that one and external network does not. Configure your DNS (MX record) or your application (test instances usually allow to override the normal mailing configuration) so that the mails are sent through that SMTP server.

There is a number of free mail server stubs available. For example hMailServer or GreenMail.

There are also SAAS solutions available like MailTrap (thanks to Adam Barnes for the remark).

I would also strongly recommend everyone to avoid using real messaging infrastructure when test emailing. This might lead to confidential data disclosure so that the company's financial and reputation loss might exceed the cost of googling of how to set up a mail server stub. This also might make gmail or other chosen mail service ban your IP or an IP range since they might consider your traffic suspicious.

  • 3
    We use mailtrap which is a good professional service. – Adam Barnes Feb 7 '18 at 17:36
  • 1
    @AdamBarnes thanks, added your remark to the answer. – Alexey R. Feb 7 '18 at 20:27
9

You could use local systems like mailcatcher or mailhog. MailHog has a web interface and SMTP port, you can use it as your SMTP target and you'll "receive" all mail in there.

If your application isn't using SMTP but an API and a mail service like sendgrid or mailchimp, this isn't the best thing to since it won't test the API access. Best thing in those cases is to add test credentials and use a non-sending endpoint for tests.

Then, using randomly generated addresses you can do any end-to-end testing that you like without exposing anything. This should be separate from testing the validity of email addresses since this will most likely accept any address.

  • 1
    Papercut is another similar application. – molnarm Feb 9 '18 at 10:21
2

In our software testing services company we follow this when we have add different users.

You can add + to your email address.

Let say you have a valid email address then you create as many users by adding , test+2@gmail.com.

All the email will go to test@gmail.com.

  • 1
    AFAIK, this is a gmail-only trick. I'm don't know which other provider allows it. I'm sure that some don't. This answer could be improved by explicitly mentioning that this trick should be used with gmail. – xDaizu Feb 8 '18 at 11:19
  • Can you please explain this test@gmail.com thing little bit. – ChathuD Aug 29 '18 at 3:40
1

If it is for testing only, you could use a programming technique called "mocking" or "monkey patching": instead of sending out real emails, your unit or functional tests "replace" function calls or objects of third-party-APIs with a mockup so that in your case, you wouldn't actually send out an email but rather mock the behaviour of sending an email.

This gives you the advantage that no data is actually sent but you can still test all the aspects you need like creating your emails, creating activation links, testing, what happens if a user clicks on a valid link or an invalid link or an expired link, or... the possibilities are endless. You can do these tests over and over again if your testing is using a dedicated test database which gets initialised every time you start a test. This way you don't fill your dev database with junk you'll never need apart from testing.

There is a nice book about testing while developing a web application called "Test-Driven Development With Python" (nicknamed: "Obey the Testing Goat!") which explains the mocking technique nicely in Chapter 19. Altough the web app in question there is based on Python / Django, if you use a different environment the basic principles should still apply. You'll only have to adapt them to your needs.

0

In our test, we clear the users mailbox as the first step so we only have to use one mailbox. The code to do this is baked into the test, rather than the application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.