javax.mail.internet.MimeBodyPart.setHeader()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中javax.mail.internet.MimeBodyPart.setHeader()方法的一些代码示例,展示了MimeBodyPart.setHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.setHeader()方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:setHeader

MimeBodyPart.setHeader介绍

[英]Set the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must be encoded as per the rules of RFC 2047.
[中]设置此标题名称的值。用此新值替换所有现有标题值。请注意,RFC 822标头必须仅包含US-ASCII字符,因此包含非US-ASCII字符的标头必须按照RFC 2047的规则进行编码。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Add an inline element to the MimeMessage, taking the content from a
  3. * {@code javax.activation.DataSource}.
  4. * <p>Note that the InputStream returned by the DataSource implementation
  5. * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
  6. * {@code getInputStream()} multiple times.
  7. * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
  8. * else, mail readers might not be able to resolve inline references correctly.
  9. * @param contentId the content ID to use. Will end up as "Content-ID" header
  10. * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
  11. * Can be referenced in HTML source via src="cid:myId" expressions.
  12. * @param dataSource the {@code javax.activation.DataSource} to take
  13. * the content from, determining the InputStream and the content type
  14. * @throws MessagingException in case of errors
  15. * @see #addInline(String, java.io.File)
  16. * @see #addInline(String, org.springframework.core.io.Resource)
  17. */
  18. public void addInline(String contentId, DataSource dataSource) throws MessagingException {
  19. Assert.notNull(contentId, "Content ID must not be null");
  20. Assert.notNull(dataSource, "DataSource must not be null");
  21. MimeBodyPart mimeBodyPart = new MimeBodyPart();
  22. mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  23. // We're using setHeader here to remain compatible with JavaMail 1.2,
  24. // rather than JavaMail 1.3's setContentID.
  25. mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
  26. mimeBodyPart.setDataHandler(new DataHandler(dataSource));
  27. getMimeMultipart().addBodyPart(mimeBodyPart);
  28. }

代码示例来源:origin: org.springframework/spring-context-support

  1. /**
  2. * Add an inline element to the MimeMessage, taking the content from a
  3. * {@code javax.activation.DataSource}.
  4. * <p>Note that the InputStream returned by the DataSource implementation
  5. * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
  6. * {@code getInputStream()} multiple times.
  7. * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
  8. * else, mail readers might not be able to resolve inline references correctly.
  9. * @param contentId the content ID to use. Will end up as "Content-ID" header
  10. * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
  11. * Can be referenced in HTML source via src="cid:myId" expressions.
  12. * @param dataSource the {@code javax.activation.DataSource} to take
  13. * the content from, determining the InputStream and the content type
  14. * @throws MessagingException in case of errors
  15. * @see #addInline(String, java.io.File)
  16. * @see #addInline(String, org.springframework.core.io.Resource)
  17. */
  18. public void addInline(String contentId, DataSource dataSource) throws MessagingException {
  19. Assert.notNull(contentId, "Content ID must not be null");
  20. Assert.notNull(dataSource, "DataSource must not be null");
  21. MimeBodyPart mimeBodyPart = new MimeBodyPart();
  22. mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  23. // We're using setHeader here to remain compatible with JavaMail 1.2,
  24. // rather than JavaMail 1.3's setContentID.
  25. mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
  26. mimeBodyPart.setDataHandler(new DataHandler(dataSource));
  27. getMimeMultipart().addBodyPart(mimeBodyPart);
  28. }

代码示例来源:origin: apache/usergrid

  1. MimeBodyPart plainPart = new MimeBodyPart();
  2. plainPart.setContent( plainText, "text/plain" );
  3. plainPart.setHeader( MIME_VERSION, "1.0" );
  4. plainPart.setHeader( CONTENT_TYPE, "text/plain; charset=iso-8859-1" );
  5. msgContent.addBodyPart( plainPart );
  6. MimeBodyPart htmlPart = new MimeBodyPart();
  7. htmlPart.setContent( htmlText, "text/html" );
  8. htmlPart.setHeader( MIME_VERSION, "1.0" );
  9. htmlPart.setHeader( CONTENT_TYPE, "text/html; charset=iso-8859-1" );
  10. msgContent.addBodyPart( htmlPart );

代码示例来源:origin: igniterealtime/Openfire

  1. html.setContent(htmlBody, "text/html; charset=UTF-8");
  2. html.setDisposition(Part.INLINE);
  3. html.setHeader("Content-Transfer-Encoding", "8bit");
  4. content.addBodyPart(html);
  5. bPart.setText(textBody, encoding);
  6. bPart.setDisposition(Part.INLINE);
  7. bPart.setHeader("Content-Transfer-Encoding", "8bit");
  8. MimeMultipart mPart = new MimeMultipart();
  9. mPart.addBodyPart(bPart);
  10. bPart.setContent(htmlBody, "text/html; charset=UTF-8");
  11. bPart.setDisposition(Part.INLINE);
  12. bPart.setHeader("Content-Transfer-Encoding", "8bit");
  13. MimeMultipart mPart = new MimeMultipart();
  14. mPart.addBodyPart(bPart);

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. public void setContentMD5(String md5) throws MessagingException {
  10. setHeader("Content-MD5", md5);
  11. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. @Override
  10. public void setContentMD5(String md5) throws MessagingException {
  11. setHeader("Content-MD5", md5);
  12. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. messageBodyPart.setDataHandler( new DataHandler( fds ) );
  2. messageBodyPart.setHeader( "Content-ID", "<" + realcontenID + ">" );

代码示例来源:origin: psi-probe/psi-probe

  1. /**
  2. * Creates the message body part.
  3. *
  4. * @param body the body
  5. * @param html the html
  6. * @return the mime body part
  7. * @throws MessagingException the messaging exception
  8. */
  9. private static MimeBodyPart createMessageBodyPart(String body, boolean html)
  10. throws MessagingException {
  11. MimeBodyPart bodyPart = new MimeBodyPart();
  12. bodyPart.setText(body);
  13. bodyPart.setHeader("content-type", html ? "text/html" : "text/plain");
  14. return bodyPart;
  15. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Set the "Content-ID" header field of this body part.
  3. * If the <code>cid</code> parameter is null, any existing
  4. * "Content-ID" is removed.
  5. *
  6. * @param cid the Content-ID
  7. * @exception IllegalWriteException if the underlying
  8. * implementation does not support modification
  9. * @exception IllegalStateException if this body part is
  10. * obtained from a READ_ONLY folder.
  11. * @exception MessagingException for other failures
  12. * @since JavaMail 1.3
  13. */
  14. public void setContentID(String cid) throws MessagingException {
  15. if (cid == null)
  16. removeHeader("Content-ID");
  17. else
  18. setHeader("Content-ID", cid);
  19. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Set the "Content-ID" header field of this body part.
  3. * If the <code>cid</code> parameter is null, any existing
  4. * "Content-ID" is removed.
  5. *
  6. * @param cid the Content-ID
  7. * @exception IllegalWriteException if the underlying
  8. * implementation does not support modification
  9. * @exception IllegalStateException if this body part is
  10. * obtained from a READ_ONLY folder.
  11. * @exception MessagingException for other failures
  12. * @since JavaMail 1.3
  13. */
  14. public void setContentID(String cid) throws MessagingException {
  15. if (cid == null)
  16. removeHeader("Content-ID");
  17. else
  18. setHeader("Content-ID", cid);
  19. }

代码示例来源:origin: rakam-io/rakam

  1. String imageId = UUID.randomUUID().toString() + "@" +
  2. UUID.randomUUID().toString() + ".mail";
  3. screenPart.setHeader("Content-ID", "<" + imageId + ">");

代码示例来源:origin: webx/citrus

  1. private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames)
  2. throws MessagingException {
  3. assertNotNull(resourceLoader, "no resourceLoader");
  4. String resourceName = inlineResource.getResourceName();
  5. Resource resource = resourceLoader.getResource(resourceName);
  6. if (!resource.exists()) {
  7. throw new MailBuilderException("Could not find resource \"" + resourceName + "\"");
  8. }
  9. DataSource ds;
  10. try {
  11. ds = new URLDataSource(resource.getURL());
  12. } catch (IOException e) {
  13. ds = new ResourceDataSource(resource);
  14. }
  15. MimeBodyPart bodyPart = new MimeBodyPart();
  16. bodyPart.setDataHandler(new DataHandler(ds));
  17. bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">");
  18. bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames));
  19. bodyPart.setDisposition("inline");
  20. multipart.addBodyPart(bodyPart);
  21. }

代码示例来源:origin: webx/citrus

  1. private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames)
  2. throws MessagingException {
  3. assertNotNull(resourceLoader, "no resourceLoader");
  4. String resourceName = inlineResource.getResourceName();
  5. Resource resource = resourceLoader.getResource(resourceName);
  6. if (!resource.exists()) {
  7. throw new MailBuilderException("Could not find resource \"" + resourceName + "\"");
  8. }
  9. DataSource ds;
  10. try {
  11. ds = new URLDataSource(resource.getURL());
  12. } catch (IOException e) {
  13. ds = new ResourceDataSource(resource);
  14. }
  15. MimeBodyPart bodyPart = new MimeBodyPart();
  16. bodyPart.setDataHandler(new DataHandler(ds));
  17. bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">");
  18. bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames));
  19. bodyPart.setDisposition("inline");
  20. multipart.addBodyPart(bodyPart);
  21. }

代码示例来源:origin: javax.mail/javax.mail-api

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. @Override
  10. public void setContentMD5(String md5) throws MessagingException {
  11. setHeader("Content-MD5", md5);
  12. }

代码示例来源:origin: javax.mail/com.springsource.javax.mail

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. public void setContentMD5(String md5) throws MessagingException {
  10. setHeader("Content-MD5", md5);
  11. }

代码示例来源:origin: com.sun.mail/jakarta.mail

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. @Override
  10. public void setContentMD5(String md5) throws MessagingException {
  11. setHeader("Content-MD5", md5);
  12. }

代码示例来源:origin: com.sun.mail/android-mail

  1. /**
  2. * Set the "Content-MD5" header field of this body part.
  3. *
  4. * @exception IllegalWriteException if the underlying
  5. * implementation does not support modification
  6. * @exception IllegalStateException if this body part is
  7. * obtained from a READ_ONLY folder.
  8. */
  9. @Override
  10. public void setContentMD5(String md5) throws MessagingException {
  11. setHeader("Content-MD5", md5);
  12. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. imagePart.setDataHandler( new DataHandler( fds ) );
  2. imagePart.setHeader( "Content-ID", "<" + contentID + ">" );

代码示例来源:origin: com.ibm.sbt/com.ibm.sbt.core

  1. public MimeBodyPart toMimeBodyPart() throws MessagingException {
  2. MimeBodyPart bodyPart = new MimeBodyPart();
  3. bodyPart.setFileName(fileName);
  4. bodyPart.setContent(content, mimeType);
  5. bodyPart.setHeader("Content-Disposition", getDisposition());
  6. bodyPart.setHeader("Content-Type", mimeType);
  7. return bodyPart;
  8. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. public void setDescription(String description, String charset) throws MessagingException {
  2. if (description == null) {
  3. removeHeader("Content-Description");
  4. }
  5. else {
  6. try {
  7. setHeader("Content-Description", MimeUtility.fold(21, MimeUtility.encodeText(description, charset, null)));
  8. } catch (UnsupportedEncodingException e) {
  9. throw new MessagingException(e.getMessage(), e);
  10. }
  11. }
  12. }

相关文章