for (int i = 0; i < address.length; i++) {
address[i] = new InternetAddress(to[i]);
}
msg.setRecipients(Message.RecipientType.TO, address);
} catch (Exception ex) {
throw new SysException(ex);
}
InternetAddress[] address = new InternetAddress[bcc.length + to.length];
try {
for (int i = 0; i < address.length; i++) {
if (i < bcc.length)
address[i] = new InternetAddress(bcc[i]);
else
address[i] = new InternetAddress(to[i - bcc.length]);
}
msg.setRecipients(Message.RecipientType.BCC, address);
} catch (Exception ex) {
throw new SysException(ex);
}
//*/
msg.setSubject(l.subject, l.charset);
msg.setSentDate(new java.util.Date());
// create and fill the first message part
Multipart mp = new MimeMultipart();
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(l.body, l.charset);
mp.addBodyPart(mbp1);
for (int i = 0; i < l.files.length; i++) {
MimeBodyPart mbp12 = new MimeBodyPart();
mbp12.setDataHandler(new DataHandler(
new FileDataSource(l.files[i])));
if((l.descriptions != null) && (l.descriptions.length > i))
mbp12.setDescription(l.descriptions[i]);
if((l.filenames != null) && (l.filenames.length > i))
mbp12.setFileName(l.filenames[i]);
else
mbp12.setFileName(l.files[i].getName());
mp.addBodyPart(mbp12);
}
// add the Multipart to the message
msg.setContent(mp);
synchronized (Transport.class) {
Transport t;
t = session.getTransport("smtp");
t.connect(host, Integer.parseInt(port), user, pwd);
t.send(msg, address);
t.close();
}
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
throw new SysException(ex);
}
}