I'm trying to send an email directly to the destination MX server, avoiding the relay smtp server. Teorically it could be possible getting the name servers list doing a query to a dns server. So, using this class, http://www.eyeasme.com/Shayne/MAILHOSTS/mailHostsLookup.html , I can get a list of the mail exchange servers of a domain.
So, once I have that, how can I proceed to send the email? I should use javax.mail or how? And if is it, how I should configure it?
Okay, so suppose we do that.
We do DNS-Lookup to fetch MX records for recipient domain. Next step would be to connect to that server and deliver the message. As hosts operating as MX have to listen on port 25 and need to accept unencrypted communication, we could do it like that:
Session
withmail.smtp.host
set to said serverWhat would we gain?
What would we lose?
Conclusion: I woudn't do that. There are alternatives (install local sendmail/postfix whatever) that are perfectly able to do the hard SMTP work for us while still simplifying the work we need to do in Java to get the mail on its way.
Working example
Here's code that worked in sending me an email by using DNS resolved MX entry for gmail.com. Guess what happend? Got classified as SPAM because google said "it's most likely not from Jan"