verify email address on Linux
The following command and link have solved the issue.
-nslookup command help to find out mail server address for examplesite.com
nslookup -type=mx examplesite.com;
-https://superuser.com/questions/224015/how-to-check-if-email-address-does-exist
The answer instruction in the link help to verfiy the email address completely
How to check if an email address exists without sending an email?
There are two methods you can sometimes use to determine if a recipient actually exists:
You can connect to the server, and issue a
VRFY
command. Very few servers support this command, but it is intended for exactly this. If the server responds with a 2.0.0 DSN, the user exists.VRFY user
You can issue a
RCPT
, and see if the mail is rejected.MAIL FROM:<>
RCPT TO:<user@domain>
If the user doesn't exist, you'll get a 5.1.1 DSN. However, just because the email is not rejected, does not mean the user exists. Some server will silently discard requests like this to prevent enumeration of their users. Other servers cannot verify the user and have to accept the message regardless.
There is also an antispam technique called greylisting, which will cause the server to reject the address initially, expecting a real SMTP server would attempt a re-delivery some time later. This will mess up attempts to validate the address.
Honestly, if you're attempting to validate an address the best approach is to use a simple regex to block obviously invalid addresses, and then send an actual email with a link back to your system that will validate the email was received. This also ensures that they user entered their actual email, not a slight typo that happens to belong to somebody else.
How do I check if an email address is valid without sending anything to it?
bucabay's answer is the way forward. What a library like that essentially does is checking for existing DNS record for (mail) servers at specified domains (A, MX, or AAAA). After that, it do what's termed callback verification. That's where you connect to the mail server, tell it you want to send to a particular email address and see if they say OK.
For callback verification, you should note greylisting servers say OK to everything so there is no 100% guarantee possible without actually sending the emails out. Here's some code I used when I did this manually. It's a patch onto the email address parser from here.
#
# Email callback verification
# Based on http://uk2.php.net/manual/en/function.getmxrr.php
#
if (strlen($bits['domain-literal'])){
$records = array($bits['domain-literal']);
}elseif (!getmxrr($bits['domain'], $mx_records, $mx_weight)){
$records = array($bits['domain']);
}else{
$mxs = array();
for ($i = 0; $i < count($mx_records); $i++){
$mxs[$mx_records[$i]] = $mx_weight[$i];
}
asort($mxs);
$records = array_keys($mxs);
}
$user_okay = false;
for ($j = 0; $j < count($records) && !$user_okay; $j++){
$fp = @fsockopen($records[$j], 25, $errno, $errstr, 2);
if($fp){
$ms_resp = "";
$ms_resp .= send_command($fp, "HELO ******.com");
$ms_resp .= send_command($fp, "MAIL FROM:<>");
$rcpt_text = send_command($fp, "RCPT TO:<" . $email . ">");
$ms_resp .= $rcpt_text;
$ms_code = intval(substr($rcpt_text, 0, 3));
if ($ms_code == 250 || $ms_code == 451){ // Accept all user account on greylisting server
$user_okay = true;
}
$ms_resp .= send_command($fp, "QUIT");
fclose($fp);
}
}
return $user_okay ? 1 : 0;
Is there a way to test if an E-Mail address exists without sending a test mail?
Short answer is no - the only way to validate it exists is to connect to the mail server and send an email to it.
Some more info : Can I check if an email address exists using .net?
"SMTP defines a command for this, but since abuse by spammers totally overwhelmed the number of legitimate uses, virtually every e-mail server in the world is configured to lie."
Another similar question : How to check if an email address exists without sending an email?
Shell script to parse a list of emails and check if their mx record is on a file
#/bin/bash
cat emails.txt |while read email
do
domain=$(echo $email | awk -F "@" '{print $2}')
dig +short mx $domain |awk '{print $2}'|sed 's/\.$//' |while read mx
do
if grep -qs $mx mx_records.txt
then
echo $email
break
fi
done
done
There is a number at the beginning of the dig output,
# dig mx apple.com +short
10 rn-mailsvcp-ppex-lapp34.apple.com.
10 rn-mailsvcp-ppex-lapp45.apple.com.
10 rn-mailsvcp-ppex-lapp44.apple.com.
so i filtered them with awk '{print $2}'
.
This script prints the matched emails as a standerd output, you can redirect the output to another file.
Related Topics
Installing Oracle Instantclient on Linux Without Setting Environment Variables
Why Is My Linux Application Pulling in The Wrong .So Library
Do I Need to "Enable" a Pcie Memory Region in a Linux 3.12 Driver
Too Many Open Files Error on Lucene
Crystalspace VS. Irrlicht VS. .....
Are Mlock()-Ed Pages Static, or Can They Be Moved in Physical Ram
Linux Transfer Parameter for Function in Declare_Work
Is Number of Frame = Number of Pages(Linux)
Linux: Send Mail After a Process Id Finishes or Is Killed
How to Assign Execute Permission to a .Sh File in Windows to Be Executed in Linux
Bash Variables: Case Sensitive or Not
How to Translate Kernel's Trap Divide Error Rsp:2B6D2Ea40450 to a Source Location
How to Find The Reason for a Dead Process Without Log File on Unix
How to Use Systemd to Restart a Service When Down