От балды

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by ky_kask, 20 Jan 2015.

  1. ky_kask

    ky_kask Member

    Joined:
    18 Nov 2009
    Messages:
    73
    Likes Received:
    81
    Reputations:
    6
    Мало ли кому потребуется


    Code:
    function mailcheck(email:string):integer;
    var
      smtp:TSMTPsend;
      domain:string;
      user: string;
      mailservers:tstringlist;
      dnsservers:tstringlist;
      x: integer;
      n: integer;
      b: boolean;
    begin
      result:=7;
      email:=getemailaddr(email);
      x := pos('@', email);
      if x <= 0 then
        exit;   //invalid address format
      domain:=separateright(email,'@');
      user:=separateLeft(email,'@');
      if (domain = '') or (user = '') then
        exit;  //invalid address format
      smtp:=tsmtpsend.create;
      smtp.AutoTLS:=true;
      mailservers:=tstringlist.create;
      dnsservers:=tstringlist.create;
      try
        dnsservers.CommaText :=GetDNS;
        dnsservers.Add('8.8.8.8');
        result := 3;
        if dnsservers.Count = 0 then
          Exit; // not DNS servers defined
        result := 2;
        b := false;
        for n := 0 to dnsservers.Count -1 do
          if GetMailServers(dnsservers[n], domain, mailservers) then
          begin
            b := true;
            break;
          end;
        if not b then
          Exit;  // DNS cannot be contacted
        result := 5;
        if mailservers.Count = 0 then
          exit;   // not defined MX record for requested domain
        b := false;
        for n := 0 to mailservers.count - 1 do
        begin
          smtp.TargetHost := mailservers[n];
          if not smtp.Login then
            Continue;
          b := true;
          if smtp.Verify(email) then
          begin
            if smtp.ResultCode < 252 then
            begin
              Result := 0; // user address confirmed!
              break;
            end;
          end
          else
            if smtp.ResultCode = 551 then
            begin
              Result := 6; // user address not confirmed!
              break;
            end;
          if not smtp.MailFrom(email, 100) then
            Continue;
          if not smtp.MailTo(email) then
          begin
            Result := 6;  // user address not confirmed!
            break;
          end
          else
          begin
            Result := 1;  // address MAY exists
            break;
          end;
        end;
        if not b then
          result := 4;   //cannot contact any mailserver;
      finally
        dnsservers.free;
        mailservers.free;
        smtp.free;
      end;
    end;
    
    var x,log,prox,tpx1:string; y,i:integer;
    label 4,5;
    begin
    y:=0;
    4:
    EnterCriticalSection (sect1);
    try
    log:=Accs.Strings[acc];
    except
    end;
    if acc<accs.Count-1 then inc(acc) else y:=1;
    if y=1 then dec(th);
    LeaveCriticalSection (sect1);
    
    if y=1 then
    begin
    destroy;
    end;
    if pos('@',log)=0 then goto 4;
    
    i:=mailcheck(log);
    EnterCriticalSection (sect1);
    if (i<=1) or (i=5) then RESULT.Add(log);
    if (i=6) or (i=7) then BAD.Add(log);
    if (i=2) or (i=3) or (i=4) then DNS.Add(log);
    LeaveCriticalSection (sect1);
    goto 4;
    end;
     
    1 person likes this.
  2. yoweb

    yoweb Banned

    Joined:
    17 Jun 2013
    Messages:
    120
    Likes Received:
    2
    Reputations:
    0
    пиши название программы всегда, чтобы по поиску в google,yandex страница с кодом находилась по названию твоей программы.
     
  3. lifescore

    lifescore Elder - Старейшина

    Joined:
    27 Aug 2011
    Messages:
    651
    Likes Received:
    511
    Reputations:
    72
    Зачем? Кому надо тот найдет. Кому лень - пускай "ложку грызут"

    А код гуд, универсален и прост. И проработает еще довольно долго)