validating an email address

My app is asking the user to enter a valid email address as part of their login.
Not sure how to tackle this but is there any way to check if the email address is valid?
My only thought would be to test is the domain is valid by a socket test??

Seems you can using nslookup and telnet but it looks tedious :wink:
https://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/

PS. Haven’t tried.
Just tested on my own mail server and it does work.

Shouldn’t be hard with declares: (or someone can come up with the regex for it themselves and use my JKRegEx class in iOSKit)
http://stackoverflow.com/questions/3139619/check-that-an-email-address-is-valid-on-ios

Jason, I think Martin wants to validate that the email actually exists and is a valid email account?
I could very well be wrong though :wink:

The WebDigi site seems to telnet to port 25 — does this work when the mail server usually requires secure email e.g. on port 587?

Also, does the following line (from the same web site above) check that the mail exchange will receive email from MY email address?

[quote=303522:@Albin Kiland]Jason, I think Martin wants to validate that the email actually exists and is a valid email account?
I could very well be wrong though ;)[/quote]
Ah, I missed that. I think you’re right but if not then Regex should do the trick.

Yes and no.
I currently use Mandrill (Mailchimp’s transactional email service) and send a welcome email to all new users.
If that email is sent from the iOS App, you can get the response from the Mandrill server.
The response can be one of the following:
“sent”, “queued”, “scheduled”, “rejected”, or “invalid”

If the status is sent then you are sure the email address is valid.
If the status is queued, you’ll never know.
If the status is rejected, this usually means the email address is invalid.
If the status is invalid, your API call went wrong.

However don’t forget that making the signup process difficult to the user makes them want to uninstall the app.

As usual, the most important question is “Why ?”.

Why do you need to verify the validity of the address ?

If you want to make sure the address used actually pertains to the user, then send him a code to enter in the app, like Google, Microsoft and others do.

1 Like

My email validation method, using the above web sites and a shell command, works with the nslookup -q=mx… command and receives the mail exchangers (e.g. the iCloud exchange below mx2.mail.icloud.com). My problem is in the next telnet step:

Dim tempShell As New Shell tempShell.TimeOut = -1 tempShell.Execute("telnet mx2.mail.icloud.com 25 ;helo")

It seems to close the telnet connection before the ‘help’ command can begin, with the shell Result:

[quote]Trying 17.172.34.12…
Connected to mx2.mail.icloud.com.
Escape character is ‘^]’.
Connection closed by foreign host.[/quote]

I have tried placing the ‘helo’ shell command on the same line (as above) or on two, but the result is the same — I get logged out. It works if I open a Terminal window and enter the same commands. Is there a problem with telnetting from within a shell? Do I need to use an Interactive shell?

This problem occurs with my Outlook.com and host mail exchanges too.

Is shell available on iOS ?

Sorry, I’ll move this question to a new post! Thanks Jeremie.

Nope.

There’s unfortunately no sure fire way to validate an email address. Best approach is simply email the user a code and verify they got it. Otherwise you will undoubtedly discard some valid addresses if you try to filter out ones that seem incorrect. Not all mail servers will reject an invalid email address or report back with any useful information. Sometimes messages just go into the abyss.