As the admin of a slightly busy drupal site, I get a lot of mailer-daemon errors generated by users entering wrong email addresses during registration. I gets worse because after not getting their password they hit the "email new password" with their username, generating more errors.

From a quick review, about 2/3 of these are actually typos in the host part of the address. This could be easily caught at registration time by doing a dns lookup on the host part of the address. After reading some doc, I understand it would be too strict to require that the host has an MX record, but we can do an ANY request. If the host has no DNS record at all, the address is surely wrong, and the user can fix it, saving the admin's time and sanity.

The patch is very simple. (Sorry I don't have the source at hand, so here is a new version of the function. Only the last part is changed):

function user_validate_mail($mail) {
  if (!$mail) return t('You must enter an e-mail address.');
  if (!valid_email_address($mail)) {
    return t('The e-mail address %mail is not valid.', array('%mail' => theme('placeholder', $mail)));
  }

  // Do a DNS check on the host
  $host = substr(strchr($mail, '@'), 1);
  if (!checkdnsrr($host, 'ANY')) {
     return t('Host @%host is not valid.', array('%host' => theme('placeholder', $host)));
  }
} 

This is my first contribution to drupal, please review and let me know if there is any problem.

Comments

moshe weitzman’s picture

Status: Needs review » Closed (won't fix)

this is best introduced as a contributed module. see hook_user('validate')

dbr’s picture

OK, I've written it has a module, with added SMTP queries to check the user part too, and I'm applying to contribute it.

markus_petrux’s picture

Oh, I already did such a module.
http://drupal.org/node/44983

Maybe I should have choosen a better name...