Search in sources :

Example 1 with ByteArrayDataSource

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);
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ByteArrayInputStream(java.io.ByteArrayInputStream) DataHandler(javax.activation.DataHandler) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteArrayDataSource(org.apache.openmeetings.util.mail.ByteArrayDataSource) Date(java.util.Date)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1 DataHandler (javax.activation.DataHandler)1 BodyPart (javax.mail.BodyPart)1 Multipart (javax.mail.Multipart)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 ByteArrayDataSource (org.apache.openmeetings.util.mail.ByteArrayDataSource)1