0

I'd like to check whether a domain (or list of domains in a SQL Server database) have mx records set, or more specifically/plainly, if the email address is real or not.

I need to do this in SQL Server/Access.

Are there any functions or scripts out there that can do this?

Thanks

Wollivan
  • 51
  • 9
  • 2
    It's very likely that with some effort this will probably work. But ask yourself: Do you **REALLY** need to do this in SQL Server? This is typically something for the application layer, not the data-layer. Also. *even if you verify an MX record to exist*, that doesn't mean the "email address is real or not". The only good way to validate if an emailaddress is "real" (valid *and* in use by an actual person/system) is to send and email with a confirmationlink or code and have the recipient confirm receiving the email. Whatever you're designing or planning: please take a step back and reconsider. – RobIII Nov 11 '19 at 15:17
  • I really appreciate the thought! In this case, without going into too much detail, it would be part of a check to make sure the email isn't fake, so its already being cleaned (bad characters, poor formatting), but that doesn't remove the fake domains e.g. '@autyhae.com' (just a random example). The check is already running in SQL Server and would be most useful if it could run alongside what is already being run, that would save the most time on the day to day checks, and most likely, dev time, as the infrastructure is already there, if the only thing that would need adding is more script. – Wollivan Nov 11 '19 at 15:29
  • https://stackoverflow.com/questions/801166/sql-script-to-find-invalid-email-addresses – Marcucciboy2 Nov 11 '19 at 15:49
  • @Marcucciboy2 How does that answer OP's question? – RobIII Nov 11 '19 at 15:51
  • @RobIII the main takeaway was intended to be the conversation around the top answer, being that `"Validating e-mail addresses in code is virtually impossible"`. I agree with your point and was initially looking for the RFC822 regex to help OP check "if the email address is real or not" in the most sane way possible – Marcucciboy2 Nov 11 '19 at 15:56
  • @Marcucciboy2 Thats a good point! This and more is already being done to the email, but thanks for the thought, and I hope they are wrong about it being impossible! – Wollivan Nov 11 '19 at 16:06
  • You can keep a Lookup table of correct domain's and atleast can verify if correct domain is used. But that will still leave actual user name to be faked/use someone else's, etc. Only option I see is how most application layers handle by sending a verification email to new sign-ups and once that is validated a bit value flag can be inserted via a Trigger firing marking the record valid. – junketsu Nov 11 '19 at 18:28
  • @Wollivan You can argue till you're blue in the face and if you insist then, by all means, go ahead and do what you (have to) do. But please read [The 100% correct way to validate email addresses](https://medium.com/hackernoon/the-100-correct-way-to-validate-email-addresses-7c4818f24643) or [There's only one way to validate an email address](https://dev.to/jerodsanto/there-s-only-one-way-to-validate-an-email-address-4i3k) – RobIII Nov 12 '19 at 02:09

0 Answers0