How to get default SMTP server name

Hi, I want to know the name default SMTP server configured in machine. How i can get this through my java code.Help me on this
[147 byte] By [deepakchandarana] at [2007-11-27 7:38:47]
# 1

You can find STMP server configured in hostname, in ask to dns of domain who is mailserver, you need to find MX records :

- look a DNS config : NS (name server) , CNAME (Alias) , MX (mailexchange) etc...

import java.util.ArrayList;

import java.util.Hashtable;

import javax.naming.*;

import javax.naming.directory.*;

public class MXLookup

{

public static void main(String args[]) throws NamingException

{

System.out.println(getMX("altern.org") + " mail servers");

}

private static ArrayList getMX(String hostName) throws NamingException

{

// Perform a DNS lookup for MX records in the domain

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 we don't have an MX record, try the machine itself

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

}

ArrayList res = new ArrayList();

NamingEnumeration en = attr.getAll();

while (en.hasMore())

{

String x = (String) en.next();

String f[] = x.split(" ");

if (f[1].endsWith(".")) f[1] = f[1].substring(0, (f[1].length() - 1));

res.add(f[1]);

}

return res;

}

}

alterna at 2007-7-12 19:19:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
As suggested, you can use DNS to get the mail server for a given domain.Even if applied to the domain amachine is running in, that doesn'tmean it's the mail server for that machine or that user. It may be agood guess, but it's only a guess.
bshannona at 2007-7-12 19:19:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...