Java Code Examples for javax.mail.internet.MimeBodyPart#setDisposition()

The following examples show how to use javax.mail.internet.MimeBodyPart#setDisposition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DSNBounce.java    From james-project with Apache License 2.0 6 votes vote down vote up
private MimeBodyPart createAttachedOriginal(Mail originalMail, TypeCode attachmentType) throws MessagingException {
    MimeBodyPart part = new MimeBodyPart();
    MimeMessage originalMessage = originalMail.getMessage();

    if (attachmentType.equals(TypeCode.HEADS)) {
        part.setContent(new MimeMessageUtils(originalMessage).getMessageHeaders(), "text/plain");
        part.setHeader("Content-Type", "text/rfc822-headers");
    } else {
        part.setContent(originalMessage, "message/rfc822");
    }

    if ((originalMessage.getSubject() != null) && (originalMessage.getSubject().trim().length() > 0)) {
        part.setFileName(originalMessage.getSubject().trim());
    } else {
        part.setFileName("No Subject");
    }
    part.setDisposition("Attachment");
    return part;
}
 
Example 2
Source File: MimePackage.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Add the specified file as an attachment
 *
 * @param fileName
 *            name of the file
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        FileDataSource ds = new FileDataSource(fileName);
        attPart.setDataHandler(new DataHandler(ds));
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(ds.getName());

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
Example 3
Source File: MimePackage.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Add an attachment with the specified content - the attachment will have a
 * content type text\plain and the specified character set
 *
 * @param content
 *            the content of the attachment
 * @param charset
 *            the character set
 * @param fileName
 *            the file name for the content-disposition header
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String content,
                           String charset,
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        attPart.setText(content, charset, PART_TYPE_TEXT_PLAIN);
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(fileName);

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
Example 4
Source File: MimeMessageBuilder.java    From james-project with Apache License 2.0 5 votes vote down vote up
public BodyPart build() throws IOException, MessagingException {
    Preconditions.checkState(!(dataAsString.isPresent() && dataAsBytes.isPresent()), "Can not specify data as bytes and data as string at the same time");
    MimeBodyPart bodyPart = new MimeBodyPart();
    if (dataAsBytes.isPresent()) {
        bodyPart.setDataHandler(
            new DataHandler(
                new ByteArrayDataSource(
                    dataAsBytes.get(),
                    type.orElse(DEFAULT_TEXT_PLAIN_UTF8_TYPE))
            ));
    } else {
        bodyPart.setDataHandler(
            new DataHandler(
                new ByteArrayDataSource(
                    dataAsString.orElse(DEFAULT_VALUE),
                    type.orElse(DEFAULT_TEXT_PLAIN_UTF8_TYPE))
            ));
    }
    if (filename.isPresent()) {
        bodyPart.setFileName(filename.get());
    }
    if (cid.isPresent()) {
        bodyPart.setContentID(cid.get());
    }
    if (disposition.isPresent()) {
        bodyPart.setDisposition(disposition.get());
    }
    List<Header> headerList = headers.build();
    for (Header header: headerList) {
        bodyPart.addHeader(header.name, header.value);
    }
    return bodyPart;
}
 
Example 5
Source File: HasAttachmentTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void multipartWithOneAttachmentShouldBeMatched() throws Exception {
    MimeMultipart mimeMultipart = new MimeMultipart();
    MimeBodyPart textPart = new MimeBodyPart();
    textPart.setDisposition(MimeMessage.INLINE);
    mimeMultipart.addBodyPart(textPart);
    MimeBodyPart attachmentPart = new MimeBodyPart();
    attachmentPart.setDisposition(MimeMessage.ATTACHMENT);
    mimeMultipart.addBodyPart(attachmentPart);
    mimeMessage.setContent(mimeMultipart);

    assertThat(testee.match(mail)).containsAll(mail.getRecipients());
}
 
Example 6
Source File: HasAttachmentTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void inlinedOnlyMultipartShouldNotBeMatched() throws Exception {
    MimeMultipart mimeMultipart = new MimeMultipart();
    MimeBodyPart part = new MimeBodyPart();
    part.setDisposition(MimeMessage.INLINE);
    part.setFileName("bahamas.png");
    mimeMultipart.addBodyPart(part);
    mimeMessage.setContent(mimeMultipart);

    assertThat(testee.match(mail)).isNull();
}
 
Example 7
Source File: TextCalendarBodyToAttachment.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MimeBodyPart createMimeBodyPartWithContentHeadersFromMimeMessage(MimeMessage mimeMessage, List<Header> contentHeaders) throws MessagingException {
    MimeBodyPart fileBody = new MimeBodyPart(mimeMessage.getRawInputStream());
    for (Header header : contentHeaders) {
        fileBody.setHeader(header.getName(), header.getValue());
    }

    fileBody.setDisposition(Part.ATTACHMENT);
    return fileBody;
}
 
Example 8
Source File: cfMAIL.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private void addAttachments( Enumeration<fileAttachment> _attach, Multipart _parent, boolean _isInline ) throws MessagingException{
	while ( _attach.hasMoreElements() ){
		fileAttachment nextFile = _attach.nextElement();
		FileDataSource fds 			= new FileDataSource( nextFile.getFilepath() );
		String mimeType = nextFile.getMimetype();
		if (mimeType == null){
			// if mime type not supplied then auto detect
			mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(nextFile.getFilepath());
     }else{
			// since mime type is not null then it the mime type has been set manually therefore
			// we need to ensure that any call to the underlying FileDataSource.getFileTypeMap()
			// returns a FileTypeMap that will map to this type
			fds.setFileTypeMap(new CustomFileTypeMap(mimeType));
		}
		
		String filename = cleanName(fds.getName());
		try {
			// encode the filename to ensure that it contains US-ASCII characters only
			filename = MimeUtility.encodeText( filename, "utf-8", "b" );
		} catch (UnsupportedEncodingException e5) {
			// shouldn't occur
		}
	  MimeBodyPart mimeAttach	= new MimeBodyPart();
	  mimeAttach.setDataHandler( new DataHandler(fds) );
		mimeAttach.setFileName( filename );

		ContentType ct = new ContentType(mimeType);
		ct.setParameter("name", filename );
		
		mimeAttach.setHeader("Content-Type", ct.toString() );

		if ( _isInline ){
       mimeAttach.setDisposition( "inline" );
       mimeAttach.addHeader( "Content-id", "<" + nextFile.getContentid() + ">" );
		}
     
		_parent.addBodyPart(mimeAttach);
	}
}
 
Example 9
Source File: MimeMessageHelper.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Add an attachment to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * @param attachmentFilename the name of the attachment as it will
 * appear in the mail (the content type will be determined by this)
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addAttachment(String, org.springframework.core.io.InputStreamSource)
 * @see #addAttachment(String, java.io.File)
 */
public void addAttachment(String attachmentFilename, DataSource dataSource) throws MessagingException {
	Assert.notNull(attachmentFilename, "Attachment filename must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	try {
		MimeBodyPart mimeBodyPart = new MimeBodyPart();
		mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
		mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));
		mimeBodyPart.setDataHandler(new DataHandler(dataSource));
		getRootMimeMultipart().addBodyPart(mimeBodyPart);
	}
	catch (UnsupportedEncodingException ex) {
		throw new MessagingException("Failed to encode attachment filename", ex);
	}
}
 
Example 10
Source File: VacationReply.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Multipart generateNotificationContentFromReasonString() throws MessagingException, IOException {
    Multipart multipart = new MimeMultipart("mixed");
    MimeBodyPart reasonPart = new MimeBodyPart();
    reasonPart.setDataHandler(
        new DataHandler(
            new ByteArrayDataSource(
                reason,
                "text/plain; charset=UTF-8")));
    reasonPart.setDisposition(MimeBodyPart.INLINE);
    multipart.addBodyPart(reasonPart);
    return multipart;
}
 
Example 11
Source File: MimePackage.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Add a multipart/alternative part to message body
 *
 * @param plainContent
 *            the content of the text/plain sub-part
 * @param htmlContent
 *            the content of the text/html sub-part
 * @param charset
 *            the character set for the part
 * @throws PackageException
 */
@PublicAtsApi
public void addAlternativePart(
                                String plainContent,
                                String htmlContent,
                                String charset ) throws PackageException {

    MimeMultipart alternativePart = new MimeMultipart("alternative");

    try {
        // create a new text/plain part
        MimeBodyPart plainPart = new MimeBodyPart();
        plainPart.setText(plainContent, charset, PART_TYPE_TEXT_PLAIN);
        plainPart.setDisposition(MimeBodyPart.INLINE);

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText(htmlContent, charset, PART_TYPE_TEXT_HTML);
        htmlPart.setDisposition(MimeBodyPart.INLINE);

        alternativePart.addBodyPart(plainPart, 0);
        alternativePart.addBodyPart(htmlPart, 1);

        MimeBodyPart mimePart = new MimeBodyPart();
        mimePart.setContent(alternativePart);

        addPart(mimePart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
Example 12
Source File: MimeMessageHelper.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Add an attachment to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * @param attachmentFilename the name of the attachment as it will
 * appear in the mail (the content type will be determined by this)
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addAttachment(String, org.springframework.core.io.InputStreamSource)
 * @see #addAttachment(String, java.io.File)
 */
public void addAttachment(String attachmentFilename, DataSource dataSource) throws MessagingException {
	Assert.notNull(attachmentFilename, "Attachment filename must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	try {
		MimeBodyPart mimeBodyPart = new MimeBodyPart();
		mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
		mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));
		mimeBodyPart.setDataHandler(new DataHandler(dataSource));
		getRootMimeMultipart().addBodyPart(mimeBodyPart);
	}
	catch (UnsupportedEncodingException ex) {
		throw new MessagingException("Failed to encode attachment filename", ex);
	}
}
 
Example 13
Source File: MessageAlteringUtils.java    From james-project with Apache License 2.0 4 votes vote down vote up
private BodyPart getBodyPart(Mail originalMail, MimeMessage originalMessage, String head) throws MessagingException, Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setText(getText(originalMail, originalMessage, head));
    part.setDisposition(javax.mail.Part.INLINE);
    return part;
}
 
Example 14
Source File: SesSendNotificationHandler.java    From smart-security-camera with GNU General Public License v3.0 4 votes vote down vote up
public Parameters handleRequest(Parameters parameters, Context context) {
	context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

	try {
		Session session = Session.getDefaultInstance(new Properties());
		MimeMessage message = new MimeMessage(session);
		message.setSubject(EMAIL_SUBJECT, "UTF-8");
		message.setFrom(new InternetAddress(System.getenv("EMAIL_FROM")));
		message.setReplyTo(new Address[] { new InternetAddress(System.getenv("EMAIL_FROM")) });
		message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(System.getenv("EMAIL_RECIPIENT")));

		MimeBodyPart wrap = new MimeBodyPart();
		MimeMultipart cover = new MimeMultipart("alternative");
		MimeBodyPart html = new MimeBodyPart();
		cover.addBodyPart(html);
		wrap.setContent(cover);
		MimeMultipart content = new MimeMultipart("related");
		message.setContent(content);
		content.addBodyPart(wrap);

		URL attachmentURL = new URL(
				System.getenv("S3_URL_PREFIX") + parameters.getS3Bucket() + '/' + parameters.getS3Key());

		StringBuilder sb = new StringBuilder();
		String id = UUID.randomUUID().toString();
		sb.append("<img src=\"cid:");
		sb.append(id);
		sb.append("\" alt=\"ATTACHMENT\"/>\n");

		MimeBodyPart attachment = new MimeBodyPart();
		DataSource fds = new URLDataSource(attachmentURL);
		attachment.setDataHandler(new DataHandler(fds));

		attachment.setContentID("<" + id + ">");
		attachment.setDisposition("attachment");

		attachment.setFileName(fds.getName());
		content.addBodyPart(attachment);

		String prettyPrintLabels = parameters.getRekognitionLabels().toString();
		prettyPrintLabels = prettyPrintLabels.replace("{", "").replace("}", "");
		prettyPrintLabels = prettyPrintLabels.replace(",", "<br>");
		html.setContent("<html><body><h2>Uploaded Filename : " + parameters.getS3Key().replace("upload/", "")
				+ "</h2><p><i>Step Function ID : " + parameters.getStepFunctionID()
				+ "</i></p><p><b>Detected Labels/Confidence</b><br><br>" + prettyPrintLabels + "</p>" + sb
				+ "</body></html>", "text/html");

		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		message.writeTo(outputStream);
		RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
		SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);

		AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.defaultClient();
		client.sendRawEmail(rawEmailRequest);

	// Convert Checked Exceptions to RuntimeExceptions to ensure that
	// they get picked up by the Step Function infrastructure
	} catch (MessagingException | IOException e) {
		throw new RuntimeException("Error in [" + context.getFunctionName() + "]", e);
	}

	context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

	return parameters;
}
 
Example 15
Source File: EmailNotificationService.java    From athenz with Apache License 2.0 4 votes vote down vote up
private MimeMessage getMimeMessage(String subject, String body, Collection<String> recipients, String from, byte[] logoImage) throws MessagingException {
    Session session = Session.getDefaultInstance(new Properties());

    // Create a new MimeMessage object.
    MimeMessage message = new MimeMessage(session);

    // Add subject, from and to lines.
    message.setSubject(subject, CHARSET_UTF_8);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(javax.mail.Message.RecipientType.BCC, InternetAddress.parse(String.join(",", recipients)));

    // Create a multipart/alternative child container.
    MimeMultipart msgBody = new MimeMultipart("alternative");

    // Create a wrapper for the HTML and text parts.
    MimeBodyPart wrap = new MimeBodyPart();

    // Set the text part.
    MimeBodyPart textPart = new MimeBodyPart();
    textPart.setContent(body, "text/plain; charset=" + CHARSET_UTF_8);

    // Set the HTML part.
    MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(body, "text/html; charset=" + CHARSET_UTF_8);

    // Add the text and HTML parts to the child container.
    msgBody.addBodyPart(textPart);
    msgBody.addBodyPart(htmlPart);

    // Add the child container to the wrapper object.
    wrap.setContent(msgBody);

    // Create a multipart/mixed parent container.
    MimeMultipart msgParent = new MimeMultipart("related");

    // Add the multipart/alternative part to the message.
    msgParent.addBodyPart(wrap);

    // Add the parent container to the message.
    message.setContent(msgParent);

    if (logoImage != null) {
        MimeBodyPart logo = new MimeBodyPart();
        logo.setContent(logoImage, "image/png");
        logo.setContentID(HTML_LOGO_CID_PLACEHOLDER);
        logo.setDisposition(MimeBodyPart.INLINE);
        // Add the attachment to the message.
        msgParent.addBodyPart(logo);
    }

    return message;
}
 
Example 16
Source File: MessageToCoreToMessage.java    From james-project with Apache License 2.0 4 votes vote down vote up
protected static MimeBodyPart toPart(String message) throws MessagingException {
    MimeBodyPart part = new MimeBodyPart();
    part.setText(message);
    part.setDisposition(MimeBodyPart.INLINE);
    return part;
}
 
Example 17
Source File: MimeMessageHelper.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
	Assert.notNull(contentId, "Content ID must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	MimeBodyPart mimeBodyPart = new MimeBodyPart();
	mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
	// We're using setHeader here to remain compatible with JavaMail 1.2,
	// rather than JavaMail 1.3's setContentID.
	mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
	mimeBodyPart.setDataHandler(new DataHandler(dataSource));
	getMimeMultipart().addBodyPart(mimeBodyPart);
}
 
Example 18
Source File: MimeMessageHelper.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
	Assert.notNull(contentId, "Content ID must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	MimeBodyPart mimeBodyPart = new MimeBodyPart();
	mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
	// We're using setHeader here to remain compatible with JavaMail 1.2,
	// rather than JavaMail 1.3's setContentID.
	mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
	mimeBodyPart.setDataHandler(new DataHandler(dataSource));
	getMimeMultipart().addBodyPart(mimeBodyPart);
}
 
Example 19
Source File: MimeMessageHelper.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
	Assert.notNull(contentId, "Content ID must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	MimeBodyPart mimeBodyPart = new MimeBodyPart();
	mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
	// We're using setHeader here to remain compatible with JavaMail 1.2,
	// rather than JavaMail 1.3's setContentID.
	mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
	mimeBodyPart.setDataHandler(new DataHandler(dataSource));
	getMimeMultipart().addBodyPart(mimeBodyPart);
}
 
Example 20
Source File: MimeMessageHelper.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
	Assert.notNull(contentId, "Content ID must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	MimeBodyPart mimeBodyPart = new MimeBodyPart();
	mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
	// We're using setHeader here to remain compatible with JavaMail 1.2,
	// rather than JavaMail 1.3's setContentID.
	mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
	mimeBodyPart.setDataHandler(new DataHandler(dataSource));
	getMimeMultipart().addBodyPart(mimeBodyPart);
}