当前位置: 首页>>代码示例>>Java>>正文


Java BodyPart.addHeader方法代码示例

本文整理汇总了Java中javax.mail.BodyPart.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.addHeader方法的具体用法?Java BodyPart.addHeader怎么用?Java BodyPart.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.BodyPart的用法示例。


在下文中一共展示了BodyPart.addHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appendIcsBody

import javax.mail.BodyPart; //导入方法依赖的package包/类
protected MimeMessage appendIcsBody(MimeMessage msg, MailMessage m) throws Exception {
	log.debug("setMessageBody for iCal message");
	// -- Create a new message --
	Multipart multipart = new MimeMultipart();

	Multipart multiBody = new MimeMultipart("alternative");
	BodyPart html = new MimeBodyPart();
	html.setDataHandler(new DataHandler(new ByteArrayDataSource(m.getBody(), "text/html; charset=UTF-8")));
	multiBody.addBodyPart(html);

	BodyPart iCalContent = new MimeBodyPart();
	iCalContent.addHeader("content-class", "urn:content-classes:calendarmessage");
	iCalContent.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"text/calendar; charset=UTF-8; method=REQUEST")));
	multiBody.addBodyPart(iCalContent);
	BodyPart body = new MimeBodyPart();
	body.setContent(multiBody);
	multipart.addBodyPart(body);

	BodyPart iCalAttachment = new MimeBodyPart();
	iCalAttachment.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"application/ics")));
	iCalAttachment.removeHeader("Content-Transfer-Encoding");
	iCalAttachment.addHeader("Content-Transfer-Encoding", "base64");
	iCalAttachment.removeHeader("Content-Type");
	iCalAttachment.addHeader("Content-Type", "application/ics");
	iCalAttachment.setFileName("invite.ics");
	multipart.addBodyPart(iCalAttachment);

	msg.setContent(multipart);
	return msg;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:33,代码来源:MailHandler.java

示例2: addAttachmentsToMultipart

import javax.mail.BodyPart; //导入方法依赖的package包/类
protected void addAttachmentsToMultipart(MimeMultipart multipart, String partDisposition,
                                         AttachmentsContentTransferEncodingResolver encodingResolver, Exchange exchange) throws MessagingException {
    LOG.trace("Adding attachments +++ start +++");
    int i = 0;
    for (Map.Entry<String, DataHandler> entry : exchange.getIn().getAttachments().entrySet()) {
        String attachmentFilename = entry.getKey();
        DataHandler handler = entry.getValue();

        if (LOG.isTraceEnabled()) {
            LOG.trace("Attachment #{}: Disposition: {}", i, partDisposition);
            LOG.trace("Attachment #{}: DataHandler: {}", i, handler);
            LOG.trace("Attachment #{}: FileName: {}", i, attachmentFilename);
        }
        if (handler != null) {
            if (shouldAddAttachment(exchange, attachmentFilename, handler)) {
                // Create another body part
                BodyPart messageBodyPart = new MimeBodyPart();
                // Set the data handler to the attachment
                messageBodyPart.setDataHandler(handler);

                if (attachmentFilename.toLowerCase().startsWith("cid:")) {
                    // add a Content-ID header to the attachment
                    // must use angle brackets according to RFC: http://www.ietf.org/rfc/rfc2392.txt
                    messageBodyPart.addHeader("Content-ID", "<" + attachmentFilename.substring(4) + ">");
                    // Set the filename without the cid
                    messageBodyPart.setFileName(attachmentFilename.substring(4));
                } else {
                    // Set the filename
                    messageBodyPart.setFileName(attachmentFilename);
                }

                LOG.trace("Attachment #" + i + ": ContentType: " + messageBodyPart.getContentType());

                if (contentTypeResolver != null) {
                    String contentType = contentTypeResolver.resolveContentType(attachmentFilename);
                    LOG.trace("Attachment #" + i + ": Using content type resolver: " + contentTypeResolver + " resolved content type as: " + contentType);
                    if (contentType != null) {
                        String value = contentType + "; name=" + attachmentFilename;
                        messageBodyPart.setHeader("Content-Type", value);
                        LOG.trace("Attachment #" + i + ": ContentType: " + messageBodyPart.getContentType());
                    }
                }

                // set Content-Transfer-Encoding using resolver if possible
                resolveContentTransferEncoding(encodingResolver, i, messageBodyPart);
                // Set Disposition
                messageBodyPart.setDisposition(partDisposition);
                // Add part to multipart
                multipart.addBodyPart(messageBodyPart);
            } else {
                LOG.trace("shouldAddAttachment: false");
            }
        } else {
            LOG.warn("Cannot add attachment: " + attachmentFilename + " as DataHandler is null");
        }
        i++;
    }
    LOG.trace("Adding attachments +++ done +++");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:60,代码来源:MailBinding.java

示例3: sendMessageCalendar

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Send a calendar message.
 * 
 * @param strRecipientsTo
 *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
 * @param strRecipientsCc
 *            The recipients list of the carbon copies .
 * @param strRecipientsBcc
 *            The recipients list of the blind carbon copies .
 * @param strSenderName
 *            The sender name.
 * @param strSenderEmail
 *            The sender email address.
 * @param strSubject
 *            The message subject.
 * @param strMessage
 *            The HTML message.
 * @param strCalendarMessage
 *            The calendar message.
 * @param bCreateEvent
 *            True to create the event, false to remove it
 * @param transport
 *            the smtp transport object
 * @param session
 *            the smtp session object
 * @throws AddressException
 *             If invalid address
 * @throws SendFailedException
 *             If an error occurred during sending
 * @throws MessagingException
 *             If a messaging error occurred
 */
protected static void sendMessageCalendar( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
        String strSenderEmail, String strSubject, String strMessage, String strCalendarMessage, boolean bCreateEvent, Transport transport, Session session )
        throws MessagingException, AddressException, SendFailedException
{
    Message msg = prepareMessage( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, session );
    msg.setHeader( HEADER_NAME, HEADER_VALUE );

    MimeMultipart multipart = new MimeMultipart( );
    BodyPart msgBodyPart = new MimeBodyPart( );
    msgBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( strMessage, AppPropertiesService.getProperty( PROPERTY_MAIL_TYPE_HTML )
            + AppPropertiesService.getProperty( PROPERTY_CHARSET ) ) ) );

    multipart.addBodyPart( msgBodyPart );

    BodyPart calendarBodyPart = new MimeBodyPart( );
    // calendarBodyPart.addHeader( "Content-Class", "urn:content-classes:calendarmessage" );
    calendarBodyPart.setContent(
            strCalendarMessage,
            AppPropertiesService.getProperty( PROPERTY_MAIL_TYPE_CALENDAR ) + AppPropertiesService.getProperty( PROPERTY_CHARSET )
                    + AppPropertiesService.getProperty( PROPERTY_CALENDAR_SEPARATOR )
                    + AppPropertiesService.getProperty( bCreateEvent ? PROPERTY_CALENDAR_METHOD_CREATE : PROPERTY_CALENDAR_METHOD_CANCEL ) );
    calendarBodyPart.addHeader( HEADER_NAME, CONSTANT_BASE64 );
    multipart.addBodyPart( calendarBodyPart );

    msg.setContent( multipart );

    sendMessage( msg, transport );
}
 
开发者ID:lutece-platform,项目名称:lutece-core,代码行数:61,代码来源:MailUtil.java


注:本文中的javax.mail.BodyPart.addHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。