SimpleSMTPHeaderpublic class SimpleSMTPHeader extends Object This class is used to construct a bare minimum
acceptable header for an email message. 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 main purpose of the class is to faciliatate the mail sending
process, by relieving the programmer from having to explicitly format
a simple message header. For example:
writer = client.sendMessageData();
if(writer == null) // failure
return false;
header =
new SimpleSMTPHeader("foobar@foo.com", "foo@bar.com" "Just testing");
header.addCC("bar@foo.com");
header.addHeaderField("Organization", "Foobar, Inc.");
writer.write(header.toString());
writer.write("This is just a test");
writer.close();
if(!client.completePendingCommand()) // failure
return false;
|
Fields Summary |
---|
private String | __subject | private String | __from | private String | __to | private StringBuffer | __headerFields | private StringBuffer | __cc |
Constructors Summary |
---|
public SimpleSMTPHeader(String from, String to, String subject)Creates a new SimpleSMTPHeader instance initialized with the given
from, to, and subject header field values.
__to = to;
__from = from;
__subject = subject;
__headerFields = new StringBuffer();
__cc = null;
|
Methods Summary |
---|
public void | addCC(java.lang.String address)Add an email address to the CC (carbon copy or courtesy copy) list.
if (__cc == null)
__cc = new StringBuffer();
else
__cc.append(", ");
__cc.append(address);
| public void | addHeaderField(java.lang.String headerField, java.lang.String value)Adds an arbitrary header field with the given value to the article
header. These headers will be written before the From, To, Subject, and
Cc fields when the SimpleSMTPHeader is convertered to a string.
An example use would be:
header.addHeaderField("Organization", "Foobar, Inc.");
__headerFields.append(headerField);
__headerFields.append(": ");
__headerFields.append(value);
__headerFields.append('\n");
| public java.lang.String | toString()Converts the SimpleSMTPHeader to a properly formatted header in
the form of a String, including the blank line used to separate
the header from the article body. The header fields CC and Subject
are only included when they are non-null.
StringBuffer header = new StringBuffer();
if (__headerFields.length() > 0)
header.append(__headerFields.toString());
header.append("From: ");
header.append(__from);
header.append("\nTo: ");
header.append(__to);
if (__cc != null)
{
header.append("\nCc: ");
header.append(__cc.toString());
}
if (__subject != null)
{
header.append("\nSubject: ");
header.append(__subject);
}
header.append('\n");
header.append('\n");
return header.toString();
|
|