I made a simple email sending application using the Java API and asked a question:
Is there a way to find out the SMTP host by knowing the email address of the person who will be logging in to send the email? And also the port?
For example, if the sender’s sender@gmail.com address is sender@gmail.com , the SMTP host is smtp.gmail.com and port 465. If the sender’s email address is sender@yahoo.com , the SMTP host is smtp.yahoomail.com and port 25.
Suppose I don't know this, is there a way to find this information using the Java API classes? Please note that I am new to java :)
Thanks in advance,
Andrea
Thank you for your responses. I tried to do the following:
public static String getMXRecordsForEmailAddress(String eMailAddress) { String returnValue = null; try { String hostName = getHostNameFromEmailAddress(eMailAddress); Record[] records = new Lookup(hostName, Type.MX).run(); if (records == null) { throw new RuntimeException("No MX records found for domain " + hostName + "."); } // return first entry (not the best solution) if (records.length > 0) { MXRecord mx = (MXRecord) records[0]; returnValue = mx.getTarget().toString(); } } catch (TextParseException e) { throw new RuntimeException(e); } System.out.println("return value = "+returnValue); return returnValue; }
But, regardless of hostName value (for example, gmail.com, yahoo.com) Record [] records = new Lookup (hostName, Type.MX) .run (); always returns null.
I'm pretty sure I missed something, but I don't know what. could you help me? Can you tell me what I'm doing wrong?
Thanks a lot,
Andrea
source share