Solved

How to validate an address of free e-mail.

Posted on 2007-04-01
3
330 Views
Last Modified: 2010-04-05
How to validate an address of free e-mail.

Ex:

Free e-mail account Hotmail, gmail, ..... not to accept
0
Comment
Question by:ProgsX
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 18833300
The only way to validat an email address is to send an email to it.. if they reply, or can contact you and say what was in teh email, then it is valid.

The reason I say this is that, even thought the RFC mentions a "VRFY" command for pop3, not many servers actually support this.
This is because spammers get paid based on how many "valid email addresses" they can provide.
It is in the user's / Mail server's best interest *not* to indicate whether an address is valid straight away.
Most servers will eventually send a "no such user" email response back to you, but this can take a few minutes.
This is still not an indication that the email address does "not exits" as users may be bounding the emails based on suspected spam content.
Free Email servers like hotmail, etc. still require an smtp server (usually port 25)
If you wish to deny entry of these accounts, you will need to create a list of them

Here's a simple example i wrote for you in Delphi

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,
// used for simple domain name check
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdGlobal, IdException;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    function IsEmailValid(emailaddress: string; var resultstring: string): boolean;
    function CheckIfDomainISNotBlocked(domain: string;  var resultstring: string): boolean;
    function LookupDomain(domain: string; var resultstring: string): boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
   resultstring: string;
begin
  if IsEmailValid(edit1.text, resultstring) then
    showmessage('valid'+#13#10 + resultstring)
  else
    showmessage('invalid'+#13#10 + resultstring);
end;

function TForm1.IsEmailValid(emailaddress: string; var resultstring: string): boolean;
var
  domain: string;
  at_index, dot_index, i: integer;
  atcount, dotcount: integer;
begin
  result := true;
  resultstring := '';
  atcount := 0;
  dotcount := 0;
  i := 1;
  while result and (i <= length(emailaddress)) do
  begin
    if emailaddress[i] = '@' then inc(atcount)
    else if not (emailaddress[i] in ['0'..'9', 'a'..'z', 'A'..'Z', '_', '.', '~']) then
    begin
      result := false;
      resultstring := 'illegal character "' + emailaddress[i] + '"';
    end;
    inc(i);
  end;
  if (atcount = 0) then
  begin
    result := false;
    resultstring := 'no "@" found';
  end
  else if (atcount > 1) then
  begin
    result := false;
    resultstring := 'Too many "@"s';
  end;
  if result then
  begin
    at_index := pos('@', emailaddress);
    result := (at_index > 1);
    if result then
    begin
      domain := copy(emailaddress, at_index + 1, maxint);
      dot_index := pos('.', domain);
      if dot_index = 0 then
      begin
        result := false;
        resultstring := 'no "." found near domain name';
      end
      else if dot_index < 2 then
      begin
        result := false;
        resultstring := 'no domain name before "."';
      end
      else if (dot_Index = length(domain)) then
      begin
        result := false;
        resultstring := '"." character can not be last character';
      end
      else
      begin
        result := CheckIfDomainISNotBlocked(domain, resultstring); // eg. hotmail.com
        if result then result := LookupDomain(domain, resultstring)
      end;
    end
    else
      resultstring := 'no name before the @ character';
  end;
end;

function TForm1.CheckIfDomainISNotBlocked(domain: string; var resultstring: string): boolean;
const
  maxnbanneddomains = 3;
  bannedDomains: array[0..(maxnbanneddomains-1)] of string = ('hotmail.com', 'yahoo.', 'gmail.com');
var
  i: integer;
begin
  result := true;
  resultstring := '';
  i := 0;
  while (result and (i < maxnbanneddomains)) do
  begin
    if (pos(bannedDomains[i], domain) > 0) then
    begin
      result := false;
      resultstring := 'banned domain: ' + bannedDomains[i];
    end
    else
      inc(i);
  end;
end;



function TForm1.LookupDomain(domain: string; var resultstring: string): boolean;
var
  TCPClientTest: TIdTCPClient;
  s: string;
begin
  result := true; //use whatever component you want to check. eg. Indy TCP client below
  resultstring := '';
// Example simple test only - if we can connect, then assume it is a valid mail server

  TCPClientTest := TIdTCPClient.Create(nil);
  try
    TCPClientTest.MaxLineAction := maException;
    TCPClientTest.Port := 25; // pop3 would be 110;
    try
      TCPClientTest.Host := domain;
      TCPClientTest.Connect(10000); // 10 second timeout
      TCPClientTest.Disconnect;
    except
      on e: exception do
      begin
        result := false;
        resultstring := 'Could not connect: ' + e.message;
      end;
    end;
  finally
    FreeAndNil(TCPClientTest);
  end;
end;

end.
0
 

Author Comment

by:ProgsX
ID: 18833439
good code

now

how to make to have to compare all the free account
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 18833729
change this part
const
  maxnbanneddomains = 3;
  bannedDomains: array[0..(maxnbanneddomains-1)] of string = ('hotmail.com', 'yahoo.', 'gmail.com');

Not sure where you'll get a list of "free" mail servers like that, but that's not really a delphi question
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now