Java Reference
In-Depth Information
/* What's it all about, Alfie? */
protected
protected
String message_subject
=
"Re: your mail"
;
/** The message CC recipient. */
protected
protected
String message_cc
=
"nobody@erewhon.com"
;
/** The text/plain message body */
protected
protected
String message_body
=
"I am unable to attend to your message, as I am busy sunning "
+
"myself on the beach in Maui, where it is warm and peaceful. "
+
"Perhaps when I return I'll get around to reading your mail. "
+
"Or not."
;
/* The text/html data. */
protected
protected
String html_data
=
"<html><head><title>My Goodness</title></head>"
+
"<body><p>You <em>do</em> look a little "
+
"<font color='green'>GREEN</font> "
+
"around the edges..."
+
"</body></html>"
;
/** The JavaMail session object */
protected
protected
Session session
;
/** The JavaMail message object */
protected
protected
Message mesg
;
/** Do the work: send the mail to the SMTP server. */
public
public
void
void
doSend
()
throws
throws
IOException
,
MessagingException
{
// We need to pass info to the mail server as a Properties, since
// JavaMail (wisely) allows room for LOTS of properties...
FileProperties props
=
new
new
FileProperties
(
MailConstants
.
PROPS_FILE_NAME
);
// Copy the value of Mail.send.host into mail.smtp.host
props
.
setProperty
(
"mail.smtp.host"
,
props
.
getProperty
(
MailConstants
.
SEND_HOST
));
// Create the Session object
session
=
Session
.
getDefaultInstance
(
props
,
null
null
);
session
.
setDebug
(
true
true
);
// Verbose!
try
try
{
// create a message
mesg
=
new
new
MimeMessage
(
session
);
// From Address - this should come from a Properties...
mesg
.
setFrom
(
new
new
InternetAddress
(
"nobody@host.domain"
));