|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.lamatek.protobeans.SMTPBean
public class SMTPBean
This bean provides a simple, easy-to-use SMTP interface for use in sending standard emails (without attachments) from Java applets.
The entire process of sending an email can be completed with just a few lines of code within a single try/catch block.
There are several ways to utilize the SMTPBean.
This first method does the whole email transmission with one line
of code. After the email is sent, the connection is closed. Additional
emails must be sent with a new SMTPBean:
(All examples assume useage from an Applet.)
try {This example creates an SMTPBean (initially connected and hailed) that sends multiple emails to the same recipient:
new SMTPBean(getCodeBase().getHost(), 25, "myemail@adress.com", "receipent@address.com", "Message Subject", "This is the actual message");
}
catch(SMTPException ex) {
ex.printStackTrace();
}
try {This example creates an SMTPBean (initially connected) that performs multiple hail and sendMessage calls to send email to many different recipients using the same connection.
SMTPBean bean = new SMTPBean(getCodeBase().getHost(), 25, "my@address.com", "recipient@address.com");
bean.sendMessage("my@address.com", "recipient@address.com", "Subject for first message", "This is message one.");
bean.sendMessage("my@address.com", "recipient@address.com", "Subject for second message", "This is message two.");
bean.logout();
}
catch(SMTPException ex) {
ex.printStackTrace();
}
try {This method creates a new SMTPBean (not connected) that sends email to one or more users.
SMTPBean bean = new SMTPBean(getCodeBase().getHost(), 25);
bean.hailAndSendMessage("my@address.com", "recipient@address.com", "Subject Header", "This is the message.");
bean.hailAndSendMessage("my@address.com", "next.recipient@address.com", "Subject Header", "This is the message.");
bean.logout(); }
catch(SMTPException ex) {
ex.printStackTrace();
}
try { SMTPBean smtp = new SMTPBean();
smtp.connect(getCodeBase().getHost(), 25);
smtp.hail("my@address.com", "recipient@address.com");
smtp.sendMessage("my@address.com", "recipient@address.com", "Email Subject", "This is the message.");
smtp.logout();
}
catch(SMTPException e) {
System.out.println(e.getMessage());
}
| Constructor Summary | |
|---|---|
SMTPBean()
Creates an initially disconnected SMTPBean. |
|
SMTPBean(java.lang.String server,
int port)
Creates a SMTPBean that attempts to establish the Socket connection to the SMTP server. |
|
SMTPBean(java.lang.String server,
int port,
java.lang.String mailfrom,
java.lang.String mailto)
Creates a SMTPBean that attempts to establish the Socket connection to the SMTP server and sends the hailing commands HELP, MAIL and RCPT. |
|
SMTPBean(java.lang.String server,
int port,
java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
Creates a SMTPBean that attempts to establish the Socket connection to the SMTP server, sends the hailing commands HELP, MAIL and RCPT and sends the message all in one step. |
|
| Method Summary | |
|---|---|
void |
connect(java.lang.String server,
int port)
This method establishes the header portion of the SMTP transaction, sending the HELP, MAIL and RCPT commands. |
java.lang.String |
getLastResponse()
This method returns the last reponse received from the SMTP Server. |
void |
hail(java.lang.String mailfrom,
java.lang.String mailto)
This method makes the necessary SMTP hailing calls to the SMTP server, including HELO, MAIL and RCPT. |
void |
hailAndSendMessage(java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
This method performs the hail and
sendMessage in one
convenient method. |
void |
logout()
This method closes all existing data streams and sockets to the SMTP server. |
void |
sendMessage(java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
This method performs the actual email transmission function. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SMTPBean()
connect, hail
and sendMessage methods must be successfully
called, in that order.
public SMTPBean(java.lang.String server,
int port)
throws SMTPException
hail
and sendMessage methods must be successfully
called, in that order.
SMTPException - If an error is received while connecting to the SMTP server.
public SMTPBean(java.lang.String server,
int port,
java.lang.String mailfrom,
java.lang.String mailto)
throws SMTPException
sendMessage.
SMTPException - If an error code is received from the Server anytime
during the connection and hailing phases.
public SMTPBean(java.lang.String server,
int port,
java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
throws SMTPException
NOTE: This constructor assumes that only one message is to be sent and
closes the Socket connection once the message is transmitted by making
a call to logout. This is
the only constructor of SMTPBean that performs this method call.
SMTPException - If an error code is received from the Server anytime
during the connection, hailing or mail transmission phases.| Method Detail |
|---|
public void connect(java.lang.String server,
int port)
throws SMTPException
SMTPException - if an error code is returned by the SMTP server.
public void hail(java.lang.String mailfrom,
java.lang.String mailto)
throws SMTPException
sendMessage method is required
to send mail.
Before a call to this method can be made, a successful call to either
connect or the SMTPBean(String, int)
constructor.
SMTPException - If any error codes are returned during the hailing phase.
public void sendMessage(java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
throws SMTPException
Before a call to this method can be made, a successful call to
connect and hail
or the SMTPBean(String, int, String, String) constructor must be made.
SMTPException - If an error message is received from the server
during email transmission.
public void hailAndSendMessage(java.lang.String mailfrom,
java.lang.String mailto,
java.lang.String subject,
java.lang.String message)
throws SMTPException
hail and
sendMessage in one
convenient method. This method is most useful when an SMTPBean
is going to send multiple emails to different recipients.
SMTPException - If an error code is received from the SMTP server
at any time during the hailing or transmission phases.public java.lang.String getLastResponse()
public void logout()
throws SMTPException
SMTPException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||