Package org.apache.commons.net.smtp
Class SimpleSMTPHeader
java.lang.Object
org.apache.commons.net.smtp.SimpleSMTPHeader
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 5322.
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 facilitate 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;
- See Also:
-
Constructor Summary
ConstructorDescriptionSimpleSMTPHeader
(String from, String to, String subject) Creates a new SimpleSMTPHeader instance initialized with the given from, to, and subject header field values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an email address to the CC (carbon copy or courtesy copy) list.void
addHeaderField
(String headerField, String value) Adds an arbitrary header field with the given value to the article header.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.
-
Constructor Details
-
SimpleSMTPHeader
Creates a new SimpleSMTPHeader instance initialized with the given from, to, and subject header field values.- Parameters:
from
- The value of theFrom:
header field. This should be the sender's email address. Must not be null.to
- The value of theTo:
header field. This should be the recipient's email address. May be nullsubject
- The value of theSubject:
header field. This should be the subject of the message. May be null
-
-
Method Details
-
addCC
Add an email address to the CC (carbon copy or courtesy copy) list.- Parameters:
address
- The email address to add to the CC list.
-
addHeaderField
Adds an arbitrary header field with the given value to the article header. These headers will be written before theFrom
,To
,Subject
, andCc
fields when the SimpleSMTPHeader is converted to a string. An example use would be:header.addHeaderField("Organization", "Foobar, Inc.");
- Parameters:
headerField
- The header field to add, not including the colon.value
- The value of the added header field.
-
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.
-