When you accept emails on the WEB I think that a lot of spam mails will fly mixed with the correct mails.
Even if you try to reply to the "Reception completed!" Email after accepting the email If you are a spammer There is no such address! Every day I see a pile of error returns piled up ... Can't this be done? !!
Since the part before the @ mark in the email address corresponds to the user I don't know until I send it
at least Let's check if the part behind the @ mark is a domain that really exists!
There used to be that, and it feels like it was built in java.
There is no particular explanation.
import java.util.Hashtable;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class MXLookup {
public static void main(String[] args) {
exec("yahoo.jp");
exec("yahoo.co.jp");
exec("126.com");
exec("127.com");
}
private static void exec(String hostname) {
System.out.println( hostname + " : " + doLookup( hostname ) + "" );
}
private static String doLookup( String hostName ) {
try {
Hashtable<String,String> env = new Hashtable<String,String>();
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 ){
return null;
}
StringBuilder sb = new StringBuilder();
for(int i=0;i<attr.size();i++){
if(sb.length() > 0){
sb.append(", ");
}
sb.append(attr.get(i));
}
return sb.toString();
} catch (NamingException e) {
return null;
}
}
}
By the way, the created system Eat incoming mail to shell This Java is called from the shell that is kicked when the mail is received in It's like filtering email senders.
that's all For your reference.
Recommended Posts