To test if a given string is indeed a valid email address is an unsolved problem in programming. The internet is full of endless threads of which regular expression would let all valid addresses pass and forbid all invalid ones. The only agreement is that there is no agreement.
So I welcomed the inspiration of my colleague Jim (at Vokomokum) to implement something straightforward: Check everything before @ to be a valid name (consisting of letters, digits and a couple other characters). Then use some library to check if everything after @ is a mail host currently known on the internet.
I was sold. That seems like a really nice trade-off between quick implementation and effectiveness. It is mostly the host name that is hard to check, so let's simply see if it exists. Mail hosts don't disappear and reappear, so it's pretty safe to ask for the DNS system to know about them at any time. The only drawback here is that you need an internet connection to run this test.
Anyway, here is an example implementation of this in Python:
The dns.resolve module has to be installed, as it is not in the Standard Library. It is in the pythondns package, so you could do
pip install pythondns