Search in sources :

Example 1 with MultipartReport

use of com.sun.mail.dsn.MultipartReport in project nhin-d by DirectProject.

the class DSNGenerator method createDSNMessage.

/**
     * Creates a DSN message message.
     * @param originalSender The original sender of the message
     * @param originalSubject The subject of the original message
     * @param postmaster The postmaster address that the DSN message will be from
     * @param recipientDSNHeaders A list of recipient DSN headers to populate the delivery status part of the DSN message
     * @param messageDSNHeaders  The message DSN headers to populate the delivery status part of the DSN message
     * @param humanReadableText The human readable part (the first part) or the DSN message
     * @return A mime message containing the full DSN message
     * @throws MessagingException
     */
public MimeMessage createDSNMessage(InternetAddress originalSender, String originalSubject, InternetAddress postmaster, List<DSNRecipientHeaders> recipientDSNHeaders, DSNMessageHeaders messageDSNHeaders, MimeBodyPart humanReadableText) throws MessagingException {
    final DeliveryStatus deliveryStatus = createDeliveryStatus(recipientDSNHeaders, messageDSNHeaders);
    // assemble multipart report
    final MultipartReport multipartReport = new MultipartReport("", deliveryStatus);
    // set name of the delivery status file
    multipartReport.getBodyPart(DELIVERY_STATUS_MULTIPART_INDEX).setFileName("status.dat");
    // set text body part
    multipartReport.setTextBodyPart(humanReadableText);
    // create mime message to send from the MultipartReport
    final Properties properties = new Properties();
    properties.setProperty("mail.from", postmaster.getAddress());
    final Session session = Session.getInstance(properties);
    final MimeMessage destinationMessage = new MimeMessage(session);
    destinationMessage.setSentDate(Calendar.getInstance().getTime());
    destinationMessage.setContent(multipartReport);
    destinationMessage.setFrom(postmaster);
    destinationMessage.addRecipient(RecipientType.TO, originalSender);
    destinationMessage.setSubject(subjectPrefix + originalSubject);
    destinationMessage.setHeader(MailStandard.Headers.InReplyTo, messageDSNHeaders.getOriginalMessageId());
    destinationMessage.saveChanges();
    return destinationMessage;
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) DeliveryStatus(com.sun.mail.dsn.DeliveryStatus) MultipartReport(com.sun.mail.dsn.MultipartReport) Properties(java.util.Properties) Session(javax.mail.Session)

Aggregations

DeliveryStatus (com.sun.mail.dsn.DeliveryStatus)1 MultipartReport (com.sun.mail.dsn.MultipartReport)1 Properties (java.util.Properties)1 Session (javax.mail.Session)1 MimeMessage (javax.mail.internet.MimeMessage)1