How to check mail address is exists or not?

后端 未结 2 1227
予麋鹿
予麋鹿 2020-12-05 10:47

I am sending email through Java using com.sun.mail.smtp.SMTPTransport.

I am successful to send the email, but SMTPTransport not giv

2条回答
  •  被撕碎了的回忆
    2020-12-05 11:14

    Thank you all for your responses.

    I am able to solve my problem through MX Record checking .

    I used this Link to resolve the problem. May this also be useful for someone.

    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 (( 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 + "'" );
    }
    

    Thank you.

提交回复
热议问题