Methods Summary |
---|
public boolean | addRecipient(RelayPath path)Add a recipient for a message using the SMTP RCPT command, specifying
a forward relay path. The sender must be set first before any
recipients may be specified, otherwise the mail server will reject
your commands.
return SMTPReply.isPositiveCompletion(rcpt(path.toString()));
|
public boolean | addRecipient(java.lang.String address)Add a recipient for a message using the SMTP RCPT command, the
recipient's email address. The sender must be set first before any
recipients may be specified, otherwise the mail server will reject
your commands.
return SMTPReply.isPositiveCompletion(rcpt("<" + address + ">"));
|
public boolean | completePendingCommand()At least one SMTPClient method ({@link #sendMessageData sendMessageData })
does not complete the entire sequence of SMTP commands to complete a
transaction. These types of commands require some action by the
programmer after the reception of a positive intermediate command.
After the programmer's code completes its actions, it must call this
method to receive the completion reply from the server and verify the
success of the entire transaction.
For example,
writer = client.sendMessage();
if(writer == null) // failure
return false;
header =
new SimpleSMTPHeader("foobar@foo.com", "foo@foobar.com", "Re: Foo");
writer.write(header.toString());
writer.write("This is just a test");
writer.close();
if(!client.completePendingCommand()) // failure
return false;
return SMTPReply.isPositiveCompletion(getReply());
|
public java.lang.String | listHelp()Fetches the system help information from the server and returns the
full string.
if (SMTPReply.isPositiveCompletion(help()))
return getReplyString();
return null;
|
public java.lang.String | listHelp(java.lang.String command)Fetches the help information for a given command from the server and
returns the full string.
if (SMTPReply.isPositiveCompletion(help(command)))
return getReplyString();
return null;
|
public boolean | login(java.lang.String hostname)Login to the SMTP server by sending the HELO command with the
given hostname as an argument. Before performing any mail commands,
you must first login.
return SMTPReply.isPositiveCompletion(helo(hostname));
|
public boolean | login()Login to the SMTP server by sending the HELO command with the
client hostname as an argument. Before performing any mail commands,
you must first login.
String name;
InetAddress host;
host = getLocalAddress();
name = host.getHostName();
if (name == null)
return false;
return SMTPReply.isPositiveCompletion(helo(name));
|
public boolean | logout()Logout of the SMTP server by sending the QUIT command.
return SMTPReply.isPositiveCompletion(quit());
|
public boolean | reset()Aborts the current mail transaction, resetting all server stored
sender, recipient, and mail data, cleaing all buffers and tables.
return SMTPReply.isPositiveCompletion(rset());
|
public java.io.Writer | sendMessageData()Send the SMTP DATA command in preparation to send an email message.
This method returns a DotTerminatedMessageWriter instance to which
the message can be written. Null is returned if the DATA command
fails.
You must not issue any commands to the SMTP server (i.e., call any
(other methods) until you finish writing to the returned Writer
instance and close it. The SMTP protocol uses the same stream for
issuing commands as it does for returning results. Therefore the
returned Writer actually writes directly to the SMTP connection.
After you close the writer, you can execute new commands. If you
do not follow these requirements your program will not work properly.
You can use the provided
{@link org.apache.commons.net.smtp.SimpleSMTPHeader}
class to construct a bare minimum header.
To construct more complicated headers you should
refer to RFC 822. When the Java Mail API is finalized, you will be
able to use it to compose fully compliant Internet text messages.
The DotTerminatedMessageWriter takes care of doubling line-leading
dots and ending the message with a single dot upon closing, so all
you have to worry about is writing the header and the message.
Upon closing the returned Writer, you need to call
{@link #completePendingCommand completePendingCommand() }
to finalize the transaction and verify its success or failure from
the server reply.
if (!SMTPReply.isPositiveIntermediate(data()))
return null;
return new DotTerminatedMessageWriter(_writer);
|
public boolean | sendNoOp()Sends a NOOP command to the SMTP server. This is useful for preventing
server timeouts.
return SMTPReply.isPositiveCompletion(noop());
|
public boolean | sendShortMessageData(java.lang.String message)A convenience method for sending short messages. This method fetches
the Writer returned by {@link #sendMessageData sendMessageData() }
and writes the specified String to it. After writing the message,
this method calls {@link #completePendingCommand completePendingCommand() }
to finalize the transaction and returns
its success or failure.
Writer writer;
writer = sendMessageData();
if (writer == null)
return false;
writer.write(message);
writer.close();
return completePendingCommand();
|
public boolean | sendSimpleMessage(java.lang.String sender, java.lang.String recipient, java.lang.String message)A convenience method for a sending short email without having to
explicitly set the sender and recipient(s). This method
sets the sender and recipient using
{@link #setSender setSender } and
{@link #addRecipient addRecipient }, and then sends the
message using {@link #sendShortMessageData sendShortMessageData }.
if (!setSender(sender))
return false;
if (!addRecipient(recipient))
return false;
return sendShortMessageData(message);
|
public boolean | sendSimpleMessage(java.lang.String sender, java.lang.String[] recipients, java.lang.String message)A convenience method for a sending short email without having to
explicitly set the sender and recipient(s). This method
sets the sender and recipients using
{@link #setSender setSender } and
{@link #addRecipient addRecipient }, and then sends the
message using {@link #sendShortMessageData sendShortMessageData }.
boolean oneSuccess = false;
int count;
if (!setSender(sender))
return false;
for (count = 0; count < recipients.length; count++)
{
if (addRecipient(recipients[count]))
oneSuccess = true;
}
if (!oneSuccess)
return false;
return sendShortMessageData(message);
|
public boolean | setSender(RelayPath path)Set the sender of a message using the SMTP MAIL command, specifying
a reverse relay path. The sender must be set first before any
recipients may be specified, otherwise the mail server will reject
your commands.
return SMTPReply.isPositiveCompletion(mail(path.toString()));
|
public boolean | setSender(java.lang.String address)Set the sender of a message using the SMTP MAIL command, specifying
the sender's email address. The sender must be set first before any
recipients may be specified, otherwise the mail server will reject
your commands.
return SMTPReply.isPositiveCompletion(mail("<" + address + ">"));
|
public boolean | verify(java.lang.String username)Verify that a username or email address is valid, i.e., that mail
can be delivered to that mailbox on the server.
int result;
result = vrfy(username);
return (result == SMTPReply.ACTION_OK ||
result == SMTPReply.USER_NOT_LOCAL_WILL_FORWARD);
|