|
Secure iNet Factory | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.jscape.inet.smtp.Smtp
Implements the basic functionality of a SMTP client.
Example Usage:
// create new instance
Smtp smtp = new Smtp("smtp.myserver.com");
// address the message
EmailMessage message = new EmailMessage();
message.setTo("mjones@myserver.com");
message.setFrom("jsmith@myserver.com");
message.setSubject("Meeting today at 8");
message setBody("see you then");
// connect, send the message, disconnect
try
{
smtp.connect();
smtp.send(message);
smtp.disconnect();
}
catch(Exception e)
{
System.out.println(e);
}
| Field Summary | |
static int |
AUTH_CRAM_MD5
CRAM_MD5 authentication. |
static int |
AUTH_LOGIN
Standard username/password authentication. |
| Constructor Summary | |
Smtp()
Constructs a new Smtp instance. |
|
Smtp(java.lang.String hostname)
Constructs a new Smtp instance. |
|
| Method Summary | |
void |
addSmtpListener(SmtpListener listener)
Adds Smtp event listener. |
void |
clearProxySettings()
Clears proxy server values. |
void |
connect()
Connects to SMTP server. |
void |
disconnect()
Disconnects from SMTP server. |
int |
getConnectTimeout()
Gets the timeout used when opening a connection to SMTP server. |
java.io.PrintStream |
getDebugStream()
Gets PrintStream used in reporting debug statements. |
java.lang.String |
getHostname()
Gets the hostname or IP address of SMTP server. |
int |
getPort()
Gets port of SMTP server. |
int |
getReadTimeout()
Gets the timeout used when reading responses from SMTP server. |
int |
getTimeout()
Deprecated. Replaced by getConnectTimeout and getReadTimeout |
boolean |
isConnected()
Checks if client is connected to SMTP server. |
boolean |
isDebug()
Gets debug level of SMTP session. |
java.lang.String |
issueCommand(java.lang.String command)
Sends command to SMTP server Command must be a valid SMTP command. |
void |
login(java.lang.String username,
java.lang.String password)
Login to SMTP server using standard username / password authentication. |
void |
login(java.lang.String username,
java.lang.String password,
int authentication)
Login to SMTP server using provided username, password and authentication mode. |
static void |
main(java.lang.String[] args)
|
void |
removeSmtpListener(SmtpListener listener)
Removes specified Smtp event listener. |
void |
send(EmailMessage message)
Sends email message. |
void |
send(EmailMessage message,
java.lang.String from,
java.lang.String to)
Sends email message. |
void |
send(java.lang.String from,
java.lang.String to,
java.lang.String subject,
java.lang.String body)
Sends basic email message. |
void |
setConnectTimeout(int timeout)
Sets the timeout for opening the connection. |
void |
setDebug(boolean debug)
Sets debugging state. |
void |
setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements. |
void |
setHeloAddress(java.lang.String heloAddress)
Sets the source address to use when issuing an EHLO or HELO command to SMTP server. |
void |
setHostname(java.lang.String hostname)
Sets the hostname or IP address of SMTP server. |
void |
setPort(int port)
Sets port of SMTP server. |
void |
setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. |
void |
setProxyHost(java.lang.String proxyHostname,
int proxyPort)
Sets the proxy hostname and port for this connection. |
void |
setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection. |
void |
setReadTimeout(int timeout)
Sets the timeout for reading responses from SMTP server. |
void |
setTimeout(int timeout)
Deprecated. Replaced by setConnectTimeout and setReadTimeout |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int AUTH_LOGIN
login(java.lang.String, java.lang.String, int),
Constant Field Valuespublic static final int AUTH_CRAM_MD5
login(java.lang.String, java.lang.String, int),
Constant Field Values| Constructor Detail |
public Smtp()
public Smtp(java.lang.String hostname)
hostname - the hostname of SMTP server| Method Detail |
public void setConnectTimeout(int timeout)
timeout - the timeout in millisecondspublic int getConnectTimeout()
public boolean isConnected()
public void setDebug(boolean debug)
debug - true to turn debugging onsetDebugStream(java.io.PrintStream)public boolean isDebug()
true if debugging is onsetDebugStream(java.io.PrintStream)public void setDebugStream(java.io.PrintStream debugStream)
debugStream - the PrintStream to send debug statements toPrintStreampublic java.io.PrintStream getDebugStream()
PrintStreampublic void setHeloAddress(java.lang.String heloAddress)
heloAddress - the IP address or hostname to usepublic void setHostname(java.lang.String hostname)
hostname - the hostname of SMTP serverpublic java.lang.String getHostname()
public void setPort(int port)
port - the port of SMTP serverpublic int getPort()
public void setReadTimeout(int timeout)
timeout - the timeout in millisecondspublic int getReadTimeout()
public void setTimeout(int timeout)
timeout - the timeout in millisecondspublic int getTimeout()
public void setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
#clearProxySettings method.
proxyUsername - the proxy usernameproxyPassword - the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname,
int proxyPort)
#clearProxySettings method.
proxyHostname - the hostname or ip address of the proxy serverproxyPort - the port of the proxy serverclearProxySettings()public void setProxyType(java.lang.String proxyType)
proxyType - The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
public void addSmtpListener(SmtpListener listener)
listener - the SmtpListener to be addedSmtpListener
public void connect()
throws SmtpException
SmtpException - thrown for I/O or SMTP related error
public void disconnect()
throws SmtpException
SmtpException - thrown to handle SMTP and I/O related errorsSmtpException
public java.lang.String issueCommand(java.lang.String command)
throws SmtpException
command - an SMTP command
SmtpException - if an I/O or SMTP related error occurs
public void login(java.lang.String username,
java.lang.String password,
int authentication)
throws SmtpException
username - the SMTP usernamepassword - the SMTP passwordauthentication - the authentication mode to use
SmtpException - thrown for I/O or SMTP related errorAUTH_LOGIN,
AUTH_CRAM_MD5
public void login(java.lang.String username,
java.lang.String password)
throws SmtpException
username - the SMTP usernamepassword - the SMTP password
SmtpException - thrown for I/O or SMTP related errorAUTH_LOGINpublic void removeSmtpListener(SmtpListener listener)
listener - the SmtpListener to be removedSmtpListener
public void send(java.lang.String from,
java.lang.String to,
java.lang.String subject,
java.lang.String body)
throws SmtpException,
MimeException
from - the from email addressto - the to email addresssubject - the subject of the email messagebody - the body of the email message
SmtpException - if an I/O or SMTP related error occurs
MimeException - if a MIME related error occurs
public void send(EmailMessage message,
java.lang.String from,
java.lang.String to)
throws SmtpException
message - an EmailMessagefrom - the email address to send this message from when
communicating with SMTP server, overriding the From header in
the messageto - the email address to send this message to when communicating
with SMTP server, overriding the To header in the message
SmtpException - if an I/O or SMTP related error occursEmailMessage
public void send(EmailMessage message)
throws SmtpException
message - an EmailMessage
SmtpException - if an I/O or SMTP related error occursEmailMessage
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
Secure iNet Factory | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||