Java Reference
In-Depth Information
"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 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
() {
// We need to pass info to the mail server as a Properties, since
// JavaMail (wisely) allows room for LOTS of properties...
Properties props
=
new
new
Properties
();
// Your LAN must define the local SMTP server as "mailhost"
// for this simple-minded version to be able to send mail...
props
.
put
(
"mail.smtp.host"
,
"mailhost"
);
// 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"
));
// TO Address
InternetAddress toAddress
=
new
new
InternetAddress
(
message_recip
);
mesg
.
addRecipient
(
Message
.
RecipientType
.
TO
,
toAddress
);
// CC Address
InternetAddress ccAddress
=
new
new
InternetAddress
(
message_cc
);
mesg
.
addRecipient
(
Message
.
RecipientType
.
CC
,
ccAddress
);
// The Subject
mesg
.
setSubject
(
message_subject
);
// Now the message body.
mesg
.
setText
(
message_body
);
// XXX I18N: use setText(msgText.getText(), charset)