Open vogthenn opened 3 years ago
please support custom naming server
Interesting. I think JEP 418: Internet-Address Resolution SPI shipped with JDK 18 might be an option to get the existing code working the way you want it to work.
My other thought is that you have provided the JNDI exception to perform the MX lookup so why not layer this code in your application? Just do the MX lookup and create a list of session objects that differ by host name. Building on your example:
Properties parent = new Properties(); //All common properties
Session[] sessions = new Session[sortedHostNames]; //From the MX lookup
for (int i=0; i<sortedHostNames.length; i++) {
Properties child = new Properties(parent);
child.put("mail.host", sortedHostNames[i]);
//set port for child???
sessions[i] = Session.getInstance(child);
}
for (Session s : sessions) {
try (Transport t = s.getTransport()) {
t.connect();
return s; //Return active session or service
} catch(MessagingException skip) {
}
}
return null; //All sites are down.
//Use returned session to build and transport your message.
I suppose the blocker would be abstractions over JakartaMail wouldn't support this behavior.
Few things that have to be dealt with internally with the project are:
java.naming
which would need to be addressed to proceed on this.
Describe the bug at a client we have a mail server that has only a registered MX record, with mulitple servers coded in there. The designated mail server has no other DNS record, though, and lookup fails with "UnknownHostException": com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtpUAT.mail.mycustomer.com, 25; timeout -1; nested exception is: java.net.UnknownHostException: smtpUAT.mail.mycustomer.com
I adapted the smtp mailserver slightly. Here the lookups: $ nslookup smtpUAT.mail.mycustomer.com Server: 10.255.253.1 Address: 10.255.253.1#53
*** Can't find smtpUAT.mail.mycustomer.com: No answer
$ nslookup -type=mx smtpUAT.mail.mycustomer.com Server: 10.255.253.1 Address: 10.255.253.1#53
smtpUAT.mail.mycustomer.com mail exchanger = 10 mailhost1.mycustomer.com. smtpUAT.mail.mycustomer.com mail exchanger = 10 mailhost2.mycustomer.com. smtpUAT.mail.mycustomer.com mail exchanger = 10 mailhost3.mycustomer.com. smtpUAT.mail.mycustomer.com mail exchanger = 10 mailhost4.mycustomer.com.
To Reproduce Steps to reproduce the behavior:
Expected behavior The RFC states, that after MX record looup, the CNAME should be used. Jakarta mail uses the standard java DNS lookup, and does not bother to do the slightly different MX record lookup, with fallback servers, if something goes wrong.
Screenshots N/A
Desktop (please complete the following information):
Smartphone (please complete the following information): N/A
Mail server:
Additional context The expecteation would be
I found this snippet on how to lookup MX records in Java: static String[] lookupMailHosts(String domainName) throws NamingException { // see: RFC 974 - Mail routing and the domain system // see: RFC 1034 - Domain names - concepts and facilities // see: http://java.sun.com/j2se/1.5.0/docs/guide/jndi/jndi-dns.html // - DNS Service Provider for the Java Naming Directory Interface (JNDI)
}