Java Reference
In-Depth Information
// 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.
Multipart mp
=
new
new
MimeMultipart
();
BodyPart textPart
=
new
new
MimeBodyPart
();
textPart
.
setText
(
message_body
);
// sets type to "text/plain"
BodyPart pixPart
=
new
new
MimeBodyPart
();
pixPart
.
setContent
(
html_data
,
"text/html"
);
// Collect the Parts into the MultiPart
mp
.
addBodyPart
(
textPart
);
mp
.
addBodyPart
(
pixPart
);
// Put the MultiPart into the Message
mesg
.
setContent
(
mp
);
// Finally, send the message!
Transport
.
send
(
mesg
);
}
catch
catch
(
MessagingException ex
) {
System
.
err
.
println
(
ex
);
ex
.
printStackTrace
(
System
.
err
);
}
}
Providing Mail Settings
Problem
You want a way to automatically provide server host, protocol, user, and password.