IP*Works!

ipworks
Class Mx

java.lang.Object
  |
  +--ipworks.Mx

public class Mx
extends java.lang.Object

The MX class enables querying of mail exchange (MX) records from a Domain Name Server (DNS). That is, it will find out the name(s) of the mail server(s) accepting email for a given email address or domain.

The class will try to find out automatically the name of a DNS server from the system's settings and set the DNSServer property.

The class operates in asynchronous mode: assigning an email address or domain name to EmailAddress property directs the class to query the DNSServer and fire the Response event for each server which handles the mail for the email address and fill out the MailServer property with the most preferred mail server and the Status event to "Ok" or an error message.

RequestId may be used to identify requests and is used in the Response event. The user may set its value before sending out requests.


Constructor Summary
Mx()
           
 
Method Summary
 void addMxEventListener(MxEventListener l)
           
 void fireError(int errorCode, java.lang.String description)
          Information about errors during data delivery.
 void fireResponse(int requestId, java.lang.String domain, java.lang.String mailServer, int precedence, int timeToLive, int statusCode, java.lang.String description)
          Fired for each MailServer accepting email for the domain.
 int getDNSPort()
          The port where the DNS server is listening.
 java.lang.String getDNSServer()
          IP address (or name) of the DNS server to query.
 java.lang.String getEmailAddress()
          Action property triggering a request to DNSServer .
 java.lang.String getLocalHost()
          The name of the local host or user-assigned IP interface through which connections are accepted or initiated.
 java.lang.String getMailServer()
          Mail server with lowest precedence value (lowest cost to reach).
 int getRequestId()
          Identifies each request.
 java.lang.String getStatus()
          Status of the request: empty while in progress, 'OK' or error message upon completition.
 void removeMxEventListener(MxEventListener l)
           
 void setDNSPort(int DNSPort)
          The port where the DNS server is listening.
 void setDNSServer(java.lang.String DNSServer)
          IP address (or name) of the DNS server to query.
 void setEmailAddress(java.lang.String emailAddress)
          Action property triggering a request to DNSServer .
 void setLocalHost(java.lang.String localHost)
          The name of the local host or user-assigned IP interface through which connections are accepted or initiated.
 void setRequestId(int requestId)
          Identifies each request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mx

public Mx()
Method Detail

getDNSPort

public int getDNSPort()
The port where the DNS server is listening. The default value is 53 but you may set DNSPort to any other value for use with experimental servers, etc.


setDNSPort

public void setDNSPort(int DNSPort)
                throws IPWorksException
The port where the DNS server is listening. The default value is 53 but you may set DNSPort to any other value for use with experimental servers, etc.


getDNSServer

public java.lang.String getDNSServer()
IP address (or name) of the DNS server to query. The class attempts to find the default DNS server for the machine where it is installed, and provide it the DNSServer property. You may later change it to any particular DNS server you want to query.

If the class cannot determine the default DNS server address, the property value will be an empty string.


setDNSServer

public void setDNSServer(java.lang.String DNSServer)
                  throws IPWorksException
IP address (or name) of the DNS server to query. The class attempts to find the default DNS server for the machine where it is installed, and provide it the DNSServer property. You may later change it to any particular DNS server you want to query.

If the class cannot determine the default DNS server address, the property value will be an empty string.


getEmailAddress

public java.lang.String getEmailAddress()
Action property triggering a request to DNSServer . Setting EmailAddress directs the class to query DNSServer at port DNSPort about MX records related to EmailAddress . The server's response is provided through one or more Response events.

After the query completes, the MailServer property is set to the best mail server and the Status property has the result description of the response.

Valid queries are email addresses like name@company.com or hostnames and domains like domain.com .


setEmailAddress

public void setEmailAddress(java.lang.String emailAddress)
                     throws IPWorksException
Action property triggering a request to DNSServer . Setting EmailAddress directs the class to query DNSServer at port DNSPort about MX records related to EmailAddress . The server's response is provided through one or more Response events.

After the query completes, the MailServer property is set to the best mail server and the Status property has the result description of the response.

Valid queries are email addresses like name@company.com or hostnames and domains like domain.com .


getMailServer

public java.lang.String getMailServer()
Mail server with lowest precedence value (lowest cost to reach). After all events are fired the MailServer property holds the name of the best mail server for the EmailAddress and the Status property holds the completition status.


getRequestId

public int getRequestId()
Identifies each request. This may be useful if several email addresses need to be resolved. Each request may be identified by the user before starting a query (setting the EmailAddress property).

If a custom value is needed for RequestId , the property must be set before setting EmailAddress . The class increments RequestId automatically after sending each request.


setRequestId

public void setRequestId(int requestId)
                  throws IPWorksException
Identifies each request. This may be useful if several email addresses need to be resolved. Each request may be identified by the user before starting a query (setting the EmailAddress property).

If a custom value is needed for RequestId , the property must be set before setting EmailAddress . The class increments RequestId automatically after sending each request.


getStatus

public java.lang.String getStatus()
Status of the request: empty while in progress, 'OK' or error message upon completition. The Status property is reset each time a request is made by setting EmailAddress . When a response comes from the DNSServer the Status property is set to "OK" in case of success or to an error message as described in the Response event.


getLocalHost

public java.lang.String getLocalHost()
The name of the local host or user-assigned IP interface through which connections are accepted or initiated. The LocalHost property contains the name of the local host as obtained by the gethostname() Winsock call or the IP address of the of interface that the user has assigned to.

In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the class accept connections only through that interface.

The value of LocalHost is not saved on the form.


setLocalHost

public void setLocalHost(java.lang.String localHost)
                  throws IPWorksException
The name of the local host or user-assigned IP interface through which connections are accepted or initiated. The LocalHost property contains the name of the local host as obtained by the gethostname() Winsock call or the IP address of the of interface that the user has assigned to.

In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the class accept connections only through that interface.

The value of LocalHost is not saved on the form.


fireResponse

public void fireResponse(int requestId,
                         java.lang.String domain,
                         java.lang.String mailServer,
                         int precedence,
                         int timeToLive,
                         int statusCode,
                         java.lang.String description)
Fired for each MailServer accepting email for the domain. (Called internally to dispatch the event.)
See Also:
MxResponseEvent

fireError

public void fireError(int errorCode,
                      java.lang.String description)
Information about errors during data delivery. (Called internally to dispatch the event.)
See Also:
MxErrorEvent

addMxEventListener

public void addMxEventListener(MxEventListener l)
                        throws java.util.TooManyListenersException

removeMxEventListener

public void removeMxEventListener(MxEventListener l)

IP*Works!

Copyright (c) 1995-2000 by /n software inc. - All rights reserved.