|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.net.email.Mailer
public class Mailer
Class to help in the creation and sending of email messages (uses Java Mail API). Many options are set via a lookup table, the following properties are recognized:
Some of the following will/may need to be implemented in the future (Ron pointed these functions as being available in the Windows Blat utility and standard RFC protocols):
organization: Organization field X-Header: Custom 'X-' header (general text) Request return receipt. Request disposition notification. prevent X-Mailer header entirely mailfromThe RFC 821 MAIL From: statement returnpath The RFC 822 Return-Path: statement sender The RFC 822 Sender: statement
| Constructor Summary | |
|---|---|
Mailer()
Initializes object to... |
|
| Method Summary | |
|---|---|
void |
addAttachment(String src)
Add a attachment to the outbound mail. |
javax.mail.Message |
buildMessage()
Construct and send email message based on contents of bean. |
javax.mail.Transport |
connectToSmtpHost()
One line summary... |
javax.mail.internet.MimeMessage |
createMessage()
Creates a new message to be sent. |
javax.mail.Authenticator |
getAuthenticator()
Get the Authenticator used to prompt user
for mail transport login ID/password (when required). |
String |
getBodyText()
Get the text to appear in the main part of the body of the message. |
DistributionList |
getDistributionList()
Get the distribution list used when creating messages. |
javax.mail.Address |
getFromAddress()
Get the "from" address to be associated with each new message created. |
AtMacros |
getInterpreter()
Get the macro interpreter used to process text strings and files. |
MimeTypes |
getMimeTypes()
Get the MimeTypes used to map file name
extensions to their corresponding MIME type. |
javax.mail.Address |
getReplyToAddress()
Get the "reply-to" address to be associated with each new message created. |
javax.mail.Session |
getSession()
Get the Session object used to connect to the
mail transports. |
String |
getSmtpHost()
Get the SMTP host to connect to. |
String |
getSmtpPassword()
Get the SMTP user's password (if necessary). |
String |
getSmtpUser()
Get the SMTP user login (not normally necessary). |
String |
getSubject()
Get the subject to use in the outbound mail. |
String |
interpret(InputStream src)
Creates a new message to be sent. |
boolean |
isDebugEnabled()
Should debug output be generated from the Java Mail API code? |
void |
sendMessage(javax.mail.Message m)
One line summary... |
void |
setAuthenticator(javax.mail.Authenticator val)
Set the Authenticator used to prompt user
for mail transport login ID/password (when required). |
void |
setBodyFrom(InputStream is,
MimeType mt)
Set the body of the text by doing a macro interpretation of a input stream. |
void |
setBodyText(String val,
MimeType mt)
Set the text to appear in the main part of the body of the message. |
void |
setDebugEnabled(boolean val)
Set whether debug output be generated from the Java Mail API code? |
void |
setFromAddress(javax.mail.Address val)
Set the "from" address to be associated with each new message created. |
void |
setFromConfig(String cfgName)
One line summary... |
void |
setFromLookup(Lookup l)
One line summary... |
void |
setInterpreter(AtMacros val)
Set the macro interpreter used to process text strings and files. |
void |
setMimeTypes(MimeTypes val)
Set the MimeTypes used to map file name
extensions to their corresponding MIME type. |
void |
setReplyToAddress(javax.mail.Address val)
Set the "reply-to" address to be associated with each new message created. |
void |
setSession(javax.mail.Session val)
Set the Session object used to connect to the
mail transports. |
void |
setSmtpHost(String val)
Set the SMTP host to connect to. |
void |
setSmtpPassword(String val)
Set the SMTP user's password (if necessary). |
void |
setSmtpUser(String val)
Set the SMTP user login (not normally necessary). |
void |
setSubject(String val)
Set the subject to use in the outbound mail. |
String |
toString()
One line summary... |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Mailer()
| Method Detail |
|---|
public void setFromConfig(String cfgName)
throws IOException,
ConfigException
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrown
IOException
ConfigExceptionpublic void setFromLookup(Lookup l)
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrownpublic void setSession(javax.mail.Session val)
Session object used to connect to the
mail transports.
val - New Session value to assign.getSession()public javax.mail.Session getSession()
Session object used to connect to the
mail transports.
setSession(javax.mail.Session)public void setAuthenticator(javax.mail.Authenticator val)
Authenticator used to prompt user
for mail transport login ID/password (when required).
val - New Authenticator value to assign.getAuthenticator()public javax.mail.Authenticator getAuthenticator()
Authenticator used to prompt user
for mail transport login ID/password (when required).
setAuthenticator(javax.mail.Authenticator)public void setDebugEnabled(boolean val)
val - New boolean value to assign.isDebugEnabled()public boolean isDebugEnabled()
setDebugEnabled(boolean)
public javax.mail.internet.MimeMessage createMessage()
throws javax.mail.MessagingException
message to be sent.
This method will create a new message and initializes with the following information:
"from" address (if available).
"to" address (if available).
"destination" address(es)
(if available).
After invoking this method, you typically only need to set the subject and message content for the message. Here is a quick example:
static void foo(Mailer mailer, String sub, String body) {
try {
Message m = mailer.createMessage();
m.setSubject(sub);
m.setContent(body,"text/plain");
mailer.send(m);
} catch (Exception e) {
e.printStackTrace();
}
}
javax.mail.MessagingException - If there is a problem creating a message for the current
Session (probably due to lack of being
properly configured), or one of the addresses we tried to set
was not in a valid form.
public String interpret(InputStream src)
throws IOException,
InterpretException
message to be sent.
This method will create a new message and initializes with the following information:
"from" address (if available).
"to" address (if available).
"destination" address(es)
(if available).
After invoking this method, you typically only need to set the subject and message content for the message. Here is a quick example:
static void foo(Mailer mailer, String sub) {
try {
Message m = mailer.createMessage();
m.setSubject(sub);
m.setContent(mailer.interpret(System.in),"text/plain");
mailer.send(m);
} catch (Exception e) {
e.printStackTrace();
}
}
IOException - If there is a problem reading information from the source
input stream.
InterpretException - If there is a problem interpretting the contents read.public void setInterpreter(AtMacros val)
val - New AtMacros value to assign.getInterpreter()public AtMacros getInterpreter()
setInterpreter(com.ccg.macros.AtMacros)
public void sendMessage(javax.mail.Message m)
throws javax.mail.internet.AddressException,
javax.mail.MessagingException,
UnsupportedEncodingException
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrown
javax.mail.internet.AddressException
javax.mail.MessagingException
UnsupportedEncodingException
public javax.mail.Message buildMessage()
throws javax.mail.MessagingException,
UnsupportedEncodingException
IllegalStateException - If the bean has not be properly initialized (not enough
information to generate a message).
javax.mail.MessagingException
UnsupportedEncodingException
public javax.mail.Transport connectToSmtpHost()
throws javax.mail.NoSuchProviderException,
javax.mail.MessagingException
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrown
javax.mail.NoSuchProviderException
javax.mail.MessagingExceptionpublic String toString()
toString in class Objectarg1 - arg1-describearg2 - arg2-describe
exc - Why thrownpublic DistributionList getDistributionList()
Whenever you create a new message, the
recipients are set to all of the entries in this distribution
list. You can add/remove items from it as needed.
public void setFromAddress(javax.mail.Address val)
Initially this value is 'null' (and you may set it to null), indicating that the "from" address should not be set by this class.
val - New Address value to assign.getFromAddress()public javax.mail.Address getFromAddress()
setFromAddress(javax.mail.Address)public void setReplyToAddress(javax.mail.Address val)
Initially this value is 'null' (and you may set it to null), indicating that the "reply-to" address should not be set by this class.
val - New Address value to assign.getReplyToAddress()public javax.mail.Address getReplyToAddress()
setReplyToAddress(javax.mail.Address)public void setSmtpHost(String val)
val - New String value to assign.getSmtpHost()public String getSmtpHost()
setSmtpHost(java.lang.String)public void setSmtpUser(String val)
val - New String value to assign.getSmtpUser()public String getSmtpUser()
setSmtpUser(java.lang.String)public void setSmtpPassword(String val)
val - New String value to assign.getSmtpPassword()public String getSmtpPassword()
setSmtpPassword(java.lang.String)public void setMimeTypes(MimeTypes val)
MimeTypes used to map file name
extensions to their corresponding MIME type.
val - New MimeTypes value to assign.getMimeTypes()public MimeTypes getMimeTypes()
MimeTypes used to map file name
extensions to their corresponding MIME type.
setMimeTypes(com.ccg.net.MimeTypes)public void setSubject(String val)
val - New String value to assign.getSubject()public String getSubject()
setSubject(java.lang.String)
public void setBodyText(String val,
MimeType mt)
val - New text value to assign (or null to clear).mt - MimeType for text (or null if you want me to guess).getBodyText()public String getBodyText()
setBodyText(java.lang.String, com.ccg.net.MimeType)
public void setBodyFrom(InputStream is,
MimeType mt)
throws IOException,
InterpretException
This method uses the interpret method to
macro process the input stream passed and sets the body of the
message to the resulting string.
is - The InputStream to read from - must not be
null.mt - The MIME type associate with the stream (can be null if you
want us to guess).
IOException - If there is a problem reading information from the source
input stream.
InterpretException - If there is a problem interpretting the contents read.public void addAttachment(String src)
src - Name of the source input to attach (can be a file name or URL).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||