use of org.apache.openmeetings.util.mail.ByteArrayDataSource in project openmeetings by apache.
the class TestSendIcalMessage method sendIcalMessage.
private void sendIcalMessage() throws Exception {
log.debug("sendIcalMessage");
// Building MimeMessage
MimeMessage mimeMessage = mailHandler.getBasicMimeMessage();
mimeMessage.setSubject(subject);
mimeMessage.addRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients, false));
// -- Create a new message --
BodyPart msg = new MimeBodyPart();
msg.setDataHandler(new DataHandler(new ByteArrayDataSource(htmlBody, "text/html; charset=\"utf-8\"")));
Multipart multipart = new MimeMultipart();
BodyPart iCalAttachment = new MimeBodyPart();
iCalAttachment.setDataHandler(new DataHandler(new javax.mail.util.ByteArrayDataSource(new ByteArrayInputStream(iCalMimeBody), "text/calendar;method=REQUEST;charset=\"UTF-8\"")));
iCalAttachment.setFileName("invite.ics");
multipart.addBodyPart(iCalAttachment);
multipart.addBodyPart(msg);
mimeMessage.setSentDate(new Date());
mimeMessage.setContent(multipart);
// -- Set some other header information --
// mimeMessage.setHeader("X-Mailer", "XML-Mail");
// mimeMessage.setSentDate(new Date());
// Transport trans = session.getTransport("smtp");
Transport.send(mimeMessage);
}
Aggregations