Setting To, CC, and BCC fields
In the following example, we are going to show how to include the To, CC, and BCC fields in our email messages:
....
String[] arrTo = {};
String[] arrCC = {};
String[] arrBCC = {};
// setting to
for (String to : arrTo) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
}
// setting cc
for (String cc : arrCC) {
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc));
}
// setting bbc
for (String bcc : arrBCC) {
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));
}
.... As you see, we have used the addRecipient method to include multiple recipients to our email message, where the first parameter denotes whether this recipient is either To, CC, or BCC by using the Message.RecipientType.* constant.