1

I'm writing this code for check yahoo account but cant response yahoo? I need write service like this site (verifyemailaddress.io) The best you can do to verify if an email address is real is to verify if there is a mail server registered to the domain name. While using the code I noticed a problem with greylisting. Greylisting is an anti-spam attempt which denies service for the first time the triple of client, sender, and address reaches the SMTP server. Greylisting will send back a temporary error (450) and therefore the address will be denied. In this case, it probably is better to accept the address as verified, because there is no better information available at that moment. import java.io.; import java.net.; import java.util.; import javax.naming.; import javax.naming.directory.*;

public class SMTP {
    private static int hear( BufferedReader in ) throws IOException {
    String line = null;
    int res = 0;

    while ( (line = in.readLine()) != null ) {
        String pfx = line.substring( 0, 3 );
        try {
            res = Integer.parseInt( pfx );
        } 
        catch (Exception ex) {
            res = -1;
        }
        if ( line.charAt( 3 ) != '-' ) break;
    }

    return res;
    }

    private static void say( BufferedWriter wr, String text ) 
    throws IOException {
    wr.write( text + "\r\n" );
    wr.flush();

    return;
    }

    private static ArrayList getMX( String hostName )
        throws NamingException {
    // Perform a DNS lookup for MX records in the domain
    Hashtable env = new Hashtable();
    env.put("java.naming.factory.initial",
            "com.sun.jndi.dns.DnsContextFactory");
    DirContext ictx = new InitialDirContext( env );
    Attributes attrs = ictx.getAttributes
                            ( hostName, new String[] { "MX" });
    Attribute attr = attrs.get( "MX" );

    // if we don't have an MX record, try the machine itself
    if (( attr == null ) || ( attr.size() == 0 )) {
        attrs = ictx.getAttributes( hostName, new String[] { "A" });
        attr = attrs.get( "A" );
        if( attr == null ) 
            throw new NamingException
                    ( "No match for name '" + hostName + "'" );
    }

    // Huzzah! we have machines to try. Return them as an array list
    // NOTE: We SHOULD take the preference into account to be absolutely
    //   correct. This is left as an exercise for anyone who cares.
    ArrayList res = new ArrayList();
    NamingEnumeration en = attr.getAll();

    while ( en.hasMore() ) {
        String x = (String) en.next();
        String f[] = x.split( " " );
        if ( f[1].endsWith( "." ) ) 
            f[1] = f[1].substring( 0, (f[1].length() - 1));
        res.add( f[1] );
    }
    return res;
    }

    public static boolean isAddressValid( String address ) {
    // Find the separator for the domain name
    int pos = address.indexOf( '@' );

    // If the address does not contain an '@', it's not valid
    if ( pos == -1 ) return false;

    // Isolate the domain/machine name and get a list of mail exchangers
    String domain = address.substring( ++pos );
    ArrayList mxList = null;
    try {
        mxList = getMX( domain );
    } 
    catch (NamingException ex) {
        return false;
    }

    // Just because we can send mail to the domain, doesn't mean that the
    // address is valid, but if we can't, it's a sure sign that it isn't
    if ( mxList.size() == 0 ) return false;

    // Now, do the SMTP validation, try each mail exchanger until we get
    // a positive acceptance. It *MAY* be possible for one MX to allow
    // a message [store and forwarder for example] and another [like
    // the actual mail server] to reject it. This is why we REALLY ought
    // to take the preference into account.
    for ( int mx = 0 ; mx < mxList.size() ; mx++ ) {
        boolean valid = false;
        try {
            int res;
            Socket skt = new Socket( (String) mxList.get( mx ), 25 );
            BufferedReader rdr = new BufferedReader
                ( new InputStreamReader( skt.getInputStream() ) );
            BufferedWriter wtr = new BufferedWriter
                ( new OutputStreamWriter( skt.getOutputStream() ) );

            res = hear( rdr );
            if ( res != 220 ) throw new Exception( "Invalid header" );
            say( wtr, "EHLO orbaker.com" );

            res = hear( rdr );
            if ( res != 250 ) throw new Exception( "Not ESMTP" );

            // validate the sender address  
            say( wtr, "MAIL FROM: <tim@orbaker.com>" );
            res = hear( rdr );
            if ( res != 250 ) throw new Exception( "Sender rejected" );

            say( wtr, "RCPT TO: <" + address + ">" );
            res = hear( rdr );

            // be polite
            say( wtr, "RSET" ); hear( rdr );
            say( wtr, "QUIT" ); hear( rdr );
            if ( res != 250 ) 
                throw new Exception( "Address is not valid!" );

            valid = true;
            rdr.close();
            wtr.close();
            skt.close();
        } 
        catch (Exception ex) {
            // Do nothing but try next host
        } 
        finally {
            if ( valid ) return true;
        }
    }
    return false;
    }

    public static void main( String args[] ) {
    String testData[] = {
        "tim@orbaker.com", // Valid address
        "fail.me@nowhere.spam", // Invalid domain name
        "arkham@bigmeanogre.net", // Invalid address
        "nosuchaddress@yahoo.com" // Failure of this method
        };

    for ( int ctr = 0 ; ctr < testData.length ; ctr++ ) {
        System.out.println( testData[ ctr ] + " is valid? " + 
            isAddressValid( testData[ ctr ] ) );
    }
    return;
    }
}

how can check yahoo account can guide me?

Saveen
  • 4,120
  • 14
  • 38
  • 41
ehsan sha
  • 83
  • 2
  • 9
  • 1
    have you considered writing a dummy mail to that account, and see if you get any errors when sending? – DarkCygnus Aug 02 '18 at 20:38
  • 1
    What is the purpose of the check? Just because an email address *exists*, doesn't mean it belongs to the person who gave you the address. Only way to verify that, is to send an actual email, asking for user to click a link to confirm: 1) email address is good, 2) the person actually requested the email. – Andreas Aug 02 '18 at 20:43
  • @DarkCygnus yahoo doesn't send any error ?!!! – ehsan sha Aug 02 '18 at 20:48
  • @Andreas I have list and we need test before send test email . I want to know how service email check works ? like verifyemailaddress.io or https://www.textmagic.com/free-tools/email-validation-tool the – ehsan sha Aug 02 '18 at 20:56
  • You need to *test* before *testing*? Isn't that redundant? – Andreas Aug 02 '18 at 21:01
  • @Andreas no because Some emails are bounce and we need check before send ? – ehsan sha Aug 03 '18 at 06:46

1 Answers1

0

You will need to mimic the create email account of yahoo. You will be needing to call two URLS, the first is when you load the create email page. This will allow you to get session values that you will be needing to the second call. The second call, it's the actual validate call that will let you know if the email exists or not. The URL for that as of time of writing is https://login.yahoo.com/account/module/create?validateField=userId.

To reverse engineer, just extract the second call details as a curl command and hard code it first. Then slowly work backwards and replace the hard coded values with dynamic values. The values are mostly coming from the initial load of the page.