ali shaikh
ali shaikh

Reputation: 1

How to check if email address exists in real world or not, by sending a request to smtp server in C#

I am getting an error in smtp connection when I send a request to stmp server.

IList<MXServer> list = new List<MXServer>();

foreach (string line in result.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
    if (line.Contains("MX preference =") && line.Contains("mail exchanger ="))
        {
        MXServer mxServer = new MXServer();
        mxServer.Preference = Int(GetStringBetween(line, "MX preference = ", ","));
        mxServer.MailExchanger = GetStringFrom(line, "mail exchanger = ");

        list.Add(mxServer);
    }
}

Upvotes: 0

Views: 544

Answers (1)

Mert G&#252;lsoy
Mert G&#252;lsoy

Reputation: 2919

By using SMTP, you can ask the server if it has the user. SMTP is a text based protocol. But there are some important points:

  1. Every server checks for spam, either this or that way. So your IP address must be a CLEAN one. (not to be listed in spam lists)
  2. Even your IP is clean, repeatedly asking for an address may result your ip to be BANNED
  3. Most service providers bans smtp ports. So you may need a static IP address.
  4. Most servers check for reverse DNS record for inbound connections. So you may need a reverse DNS (PTR) record.
  5. You may need an SPF record.
  6. There are 2 ways to ask an SMTP server: a. VRFY command b. RCPT TO
  7. Most servers are not replying VRFY because of security reasons.

So here is an SMTP session example:

C: MAIL FROM:<[email protected]>
S: 250 OK
C: RCPT TO:<[email protected]>
S: 250 OK
C: RCPT TO:<[email protected]>
S: 250 OK 

Basically if you get 250 ... answer for a RCPT TO command 90% the email address is ok. Then you can abort the connection.

Upvotes: 1

Related Questions