}
);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
msg.setReplyTo(new Address[]{addressFrom});
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
//msg.setRecipients(Message.RecipientType.BCC, addressTo);
MimeMultipart multipart = new MimeMultipart("alternative");
if(attachmentURL!=null) {
MimeBodyPart filePart = new MimeBodyPart();
filePart.setFileName( attachmentFileName );
URL url = new URL(attachmentURL);
URLConnection connection = url.openConnection();
connection.setRequestProperty( "User-Agent","OpenForum");
ByteArrayDataSource ds = new ByteArrayDataSource(connection.getInputStream(), attachmentMimeType);
filePart.setDataHandler(new DataHandler(ds));
multipart.addBodyPart(filePart);
}
MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(textMessage, "text/plain");
multipart.addBodyPart(textPart);
if(htmlMessage!=null) {
MimeBodyPart htmlPart = new MimeBodyPart();
String htmlData = htmlMessage;
htmlPart.setContent(htmlData, "text/html");
multipart.addBodyPart(htmlPart);
}
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(multipart);
Transport transport = session.getTransport(addressTo[0]);
transport.addTransportListener(this);
transport.connect();
// Sending Message
for(Address to: addressTo) {
try{
//msg.setRecipients(RecipientType.TO,new Address[]{to});
//Transport.send(msg);
msg.setRecipients(RecipientType.TO,new Address[]{to});
transport.sendMessage(msg,new Address[]{to});
} catch (Exception e) {
//messageSendFailed(e,msg);
transport.close();
transport.connect();