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


Java MimeBodyPart.setHeader方法代码示例

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


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

示例1: addAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public static String addAttachment(MimeMultipart mm, String path)
{
	if(count == Integer.MAX_VALUE)
	{
		count = 0;
	}
	int cid = count++;
       try
	{
   		java.io.File file = new java.io.File(path);
   		MimeBodyPart mbp = new MimeBodyPart();
   		mbp.setDisposition(MimeBodyPart.INLINE);
   		mbp.setContent(new MimeMultipart("mixed"));
   		mbp.setHeader("Content-ID", "<" + cid + ">");
		mbp.setDataHandler(new DataHandler(new FileDataSource(file)));
        mbp.setFileName(new String(file.getName().getBytes("GBK"), "ISO-8859-1"));
        mm.addBodyPart(mbp);
        return String.valueOf(cid);
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
       return "";
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:26,代码来源:EmailUtil.java

示例2: addBodyPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Method addBodyPart
 * 
 * @param mp 
 * @param dh 
 */
private static void addBodyPart(MimeMultipart mp, DataHandler dh) {
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    try {
        messageBodyPart.setDataHandler(dh);
        String contentType = dh.getContentType();
        if ((contentType == null) || (contentType.trim().length() == 0)) {
            contentType = "application/octet-stream";
        }
        System.out.println("Content type: " + contentType);
        messageBodyPart.setHeader(HEADER_CONTENT_TYPE, contentType);
        messageBodyPart.setHeader(
                HEADER_CONTENT_TRANSFER_ENCODING,
                "binary");    // Safe and fastest for anything other than mail
        mp.addBodyPart(messageBodyPart);
    } catch (javax.mail.MessagingException e) {
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:Tester.java

示例3: addToMimeMultipart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public void addToMimeMultipart (@Nonnull final MimeMultipart aMimeMultipart) throws MessagingException
{
  ValueEnforcer.notNull (aMimeMultipart, "MimeMultipart");

  final MimeBodyPart aMimeBodyPart = new MimeBodyPart ();

  aMimeBodyPart.setHeader (CHttpHeader.CONTENT_ID, getId ());
  // !IMPORTANT! DO NOT CHANGE the order of the adding a DH and then the last
  // headers
  // On some tests the datahandler did reset content-type and transfer
  // encoding, so this is now the correct order
  aMimeBodyPart.setDataHandler (new DataHandler (_getAsDataSource ()));

  // After DataHandler!!
  aMimeBodyPart.setHeader (CHttpHeader.CONTENT_TYPE, getMimeType ());
  aMimeBodyPart.setHeader (CHttpHeader.CONTENT_TRANSFER_ENCODING, getContentTransferEncoding ().getID ());

  aMimeMultipart.addBodyPart (aMimeBodyPart);
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:20,代码来源:WSS4JAttachment.java

示例4: part

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private static MimeBodyPart part(final ChainedHttpConfig config, final MultipartContent.MultipartPart multipartPart) throws MessagingException {
    final MimeBodyPart bodyPart = new MimeBodyPart();
    bodyPart.setDisposition("form-data");

    if (multipartPart.getFileName() != null) {
        bodyPart.setFileName(multipartPart.getFileName());
        bodyPart.setHeader("Content-Disposition", format("form-data; name=\"%s\"; filename=\"%s\"", multipartPart.getFieldName(), multipartPart.getFileName()));

    } else {
        bodyPart.setHeader("Content-Disposition", format("form-data; name=\"%s\"", multipartPart.getFieldName()));
    }

    bodyPart.setDataHandler(new DataHandler(new EncodedDataSource(config, multipartPart.getContentType(), multipartPart.getContent())));
    bodyPart.setHeader("Content-Type", multipartPart.getContentType());

    return bodyPart;
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:18,代码来源:CoreEncoders.java

示例5: getMultiPartMsg

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private Multipart getMultiPartMsg(String message) throws MessagingException {
  Multipart mp = new MimeMultipart();
  MimeBodyPart bodyPart = new MimeBodyPart();
  bodyPart.setHeader("Content-Type", mimeType);
  bodyPart.setContent(message, mimeType);
  mp.addBodyPart(bodyPart);
  return mp;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:9,代码来源:EmailService.java

示例6: buildHtmlBodyPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private MimeBodyPart buildHtmlBodyPart() throws MessagingException {
    final MimeMultipart htmlContent = new MimeMultipart("related");

    final MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(html, "text/html; charset=utf-8");
    htmlContent.addBodyPart(htmlPart);

    for (final Map.Entry<String, String> entry : contentIdsToFilePaths.entrySet()) {
        final MimeBodyPart embeddedImageBodyPart = new MimeBodyPart();
        String imageFilePath = entry.getValue();
        File imageFile = new File(imageFilePath);

        if (!imageFile.exists()) {
            final File imagesDir = findImagesDirectory();
            if (imagesDir != null) {
                imageFile = new File(imagesDir, imageFilePath);
                if (imageFile.exists()) {
                    try {
                        imageFilePath = imageFile.getCanonicalPath();
                    } catch (final IOException e) {
                        // ignore let freemarker fail and log the exception
                        // up the chain when it cannot find the image file
                    }
                }
            }
        }
        final DataSource fds = new FileDataSource(imageFilePath);
        embeddedImageBodyPart.setDataHandler(new DataHandler(fds));
        embeddedImageBodyPart.setHeader("Content-ID", entry.getKey());
        htmlContent.addBodyPart(embeddedImageBodyPart);
    }

    final MimeBodyPart htmlBodyPart = new MimeBodyPart();
    htmlBodyPart.setContent(htmlContent);
    return htmlBodyPart;
}
 
开发者ID:blackducksoftware,项目名称:hub-email-extension,代码行数:37,代码来源:MimeMultipartBuilder.java

示例7: getBodyPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public MimeBodyPart getBodyPart() throws AS2MessageException {
    try {
        saveReportValues();
        MimeBodyPart bodyPart = new MimeBodyPart();
        bodyPart.setContent(multiPart);
        boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
        bodyPart.setHeader("Content-Type", isContentTypeFolded? multiPart.getContentType():multiPart.getContentType().replaceAll("\\s"," "));
        return bodyPart;
    }
    catch (Exception e) {
        throw new AS2MessageException("Unable to construct the body part", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:14,代码来源:DispositionNotification.java

示例8: getMessage

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public synchronized MimeMessage getMessage() throws Exception {

		MimeMessage msg = null;
		try {
			InternetAddress from[] = { new InternetAddress(getDe().trim()) };
			InternetAddress resp[] = { new InternetAddress(getEmailResp().trim()) };
			msg = new MimeMessage(getSession());
			msg.setFrom(from[0]);
			msg.setReplyTo(resp);

			InternetAddress[] address = null;

			address = new InternetAddress[] { new InternetAddress(getPara().trim()) };

			msg.setRecipients(Message.RecipientType.TO, address);
			msg.setSubject(getAssunto().trim());

			MimeBodyPart mbp = new MimeBodyPart();

			mbp.setContent(getCorpo().trim(), getFormato());
			mbp.setHeader("MIME-Version", "1.0");
			mbp.setHeader("Content-Type", getFormato() + ";charset=\"" + getCharset() + "\"");

			MimeMultipart content = new MimeMultipart("alternative");
			content.addBodyPart(mbp);

			msg.setContent(content);

			msg.setHeader("MIME-Version", "1.0");
			msg.setHeader("Content-Type", content.getContentType());
			msg.setHeader("X-Mailer", "Java-Mailer");

			msg.setSentDate(Calendar.getInstance().getTime());
		}
		catch (Exception e) {
			e.printStackTrace();
		}

		return msg;
	}
 
开发者ID:cams7,项目名称:erp,代码行数:41,代码来源:EmailBean.java

示例9: sendGMail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
     * Fetch a list of Gmail labels attached to the specified account.
     *
     * @return List of Strings labels.
     */
    private List<String> sendGMail() throws Exception {
        List<String> retVal = new ArrayList<>();
        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sendGMail begin");
            debugLogFileWriter.flush();
        }

        //create the message
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        MimeMessage mimeMessage = new MimeMessage(session);

        mimeMessage.setFrom(new InternetAddress("me"));
        mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO,
                new InternetAddress(mEmailTo));
        mimeMessage.setSubject(mSubject);

        MimeBodyPart mimeBodyText = new MimeBodyPart();
        mimeBodyText.setContent(mMessage, "text/html");
        mimeBodyText.setHeader("Content-Type", "text/html; charset=\"UTF-8\"");

        Multipart mp = new MimeMultipart();
        mp.addBodyPart(mimeBodyText);

        if (mAttachments != null && mAttachments.size() > 0) {
            for (String attachment : mAttachments) {
                File attach = new File(attachment);
                if (!attach.exists()) {
                    throw new IOException("File not found");
                }

                MimeBodyPart mimeBodyAttachments = new MimeBodyPart();
                String fileName = attach.getName();
                FileInputStream is = new FileInputStream(attach);
                DataSource source = new ByteArrayDataSource(is, "application/zip");
                mimeBodyAttachments.setDataHandler(new DataHandler(source));
                mimeBodyAttachments.setFileName(fileName);
                mimeBodyAttachments.setHeader("Content-Type", "application/zip" + "; name=\"" + fileName + "\"");
                mimeBodyAttachments.setDisposition(MimeBodyPart.ATTACHMENT);
                mp.addBodyPart(mimeBodyAttachments);
            }
//            mimeBodyAttachments.setHeader("Content-Transfer-Encoding", "base64");
        }

        mimeMessage.setContent(mp);

//        mimeMessage.setText(mMessage);
        //encode in base64url string
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        mimeMessage.writeTo(bytes);
        String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());

        //create the message
        Message message = new Message();
        message.setRaw(encodedEmail);

        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail begin");
            debugLogFileWriter.flush();
        }

        //send the message ("me" => the current selected google account)
        Message result = mGmailService.users().messages().send("me", message).execute();

        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail ended with result:\n")
                    .append(result.toPrettyString());
            debugLogFileWriter.flush();
        }

        retVal.add(AndiCar.getAppResources().getString(R.string.gen_mail_sent));
        return retVal;
    }
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:80,代码来源:SendGMailTask.java

示例10: send

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Override
public void send(List<String> to, List<String> cc, List<String> ci, String object, String content, boolean htmlContent, Set<Attachment> attachments) {
    if (CollectionUtils.isEmpty(to)) {
        throw new IllegalArgumentException("to must be defined.");
    }
    if (isBlank(content)) {
        throw new IllegalArgumentException("content must be defined.");
    }

    if (attachments == null) {
        sendSimpleMail(to, cc, ci, object, content, htmlContent);
    } else {
        Session session = Session.getDefaultInstance(new Properties());
        MimeMessage message = new MimeMessage(session);
        try {
            message.setSubject(object);
            message.setFrom(new InternetAddress(from));
            addRecipients(message, javax.mail.Message.RecipientType.TO, to);
            addRecipients(message, javax.mail.Message.RecipientType.CC, cc);
            addRecipients(message, javax.mail.Message.RecipientType.BCC, ci);

            MimeBodyPart wrap = new MimeBodyPart();
            MimeMultipart cover = new MimeMultipart("alternative");
            MimeBodyPart html = new MimeBodyPart();
            cover.addBodyPart(html);

            wrap.setContent(cover);

            MimeMultipart multiPartContent = new MimeMultipart("related");
            message.setContent(multiPartContent);
            multiPartContent.addBodyPart(wrap);

            for (Attachment attachment : attachments) {

                MimeBodyPart attachmentPart = new MimeBodyPart();

                attachmentPart.setHeader("Content-ID", "<" + attachment.getId() + ">");
                attachmentPart.setFileName(attachment.getFileName());
                attachmentPart.setContent(attachment.getContent(), attachment.mineType());

                multiPartContent.addBodyPart(attachmentPart);
            }

            html.setContent(content, MINE_TEXT_HTML);

            // Send the email.
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            message.writeTo(outputStream);
            RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));

            SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);

            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();
            client.setRegion(region);

            client.sendRawEmail(rawEmailRequest);

        } catch (MessagingException | IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:kodokojo,项目名称:kodokojo,代码行数:63,代码来源:SesEmailSender.java

示例11: generateMimeMessage

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Nonnull
public static MimeMessage generateMimeMessage (@Nonnull final ESOAPVersion eSOAPVersion,
                                               @Nonnull final Document aSOAPEnvelope,
                                               @Nullable final ICommonsList <WSS4JAttachment> aEncryptedAttachments) throws MessagingException
{
  ValueEnforcer.notNull (eSOAPVersion, "SOAPVersion");
  ValueEnforcer.notNull (aSOAPEnvelope, "SOAPEnvelope");

  final Charset aCharset = AS4XMLHelper.XWS.getCharset ();
  final SoapMimeMultipart aMimeMultipart = new SoapMimeMultipart (eSOAPVersion, aCharset);
  final EContentTransferEncoding eCTE = EContentTransferEncoding.BINARY;
  final String sContentType = eSOAPVersion.getMimeType (aCharset).getAsString ();

  {
    // Message Itself
    final MimeBodyPart aMessagePart = new MimeBodyPart ();
    aMessagePart.setContent (new DOMSource (aSOAPEnvelope), sContentType);
    aMessagePart.setHeader (CHttpHeader.CONTENT_TRANSFER_ENCODING, eCTE.getID ());
    aMimeMultipart.addBodyPart (aMessagePart);
  }

  if (aEncryptedAttachments != null)
    for (final WSS4JAttachment aEncryptedAttachment : aEncryptedAttachments)
    {
      aEncryptedAttachment.addToMimeMultipart (aMimeMultipart);
    }

  // Build main message
  final MimeMessage aMsg = new MimeMessage ((Session) null);
  aMsg.setContent (aMimeMultipart);
  aMsg.saveChanges ();

  if (false)
    try
    {
      final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ();
      aMsg.writeTo (aBAOS);
      final String s = aBAOS.getAsString (StandardCharsets.UTF_8);
      if (s.length () > 0)
        System.out.println (s);
    }
    catch (final Throwable t)
    {}

  return aMsg;
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:47,代码来源:MimeMessageCreator.java

示例12: sendEmail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public void sendEmail(String html, List<Attachment> attachments, InternetAddress recipient, String title)
        throws MessagingException, UnsupportedEncodingException {
    Properties properties = new Properties();
    properties.put("mail.smtp.host", smtpHost);
    properties.put("mail.smtp.port", smtpPort);
    properties.put("mail.smtp.auth", smtpAuth);
    properties.put("mail.smtp.starttls.enable", smtpStarttls);
    properties.put("mail.user", userName);
    properties.put("mail.password", password);

    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };

    Session session = Session.getInstance(properties, auth);

    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(mailFrom, mailFromName));

    InternetAddress[] toAddresses = { recipient };

    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(javax.mail.internet.MimeUtility.encodeText(title, "UTF-8", "Q"));
    msg.setSentDate(new Date());

    MimeBodyPart wrap = new MimeBodyPart();

    MimeMultipart cover = new MimeMultipart("alternative");

    MimeBodyPart htmlContent = new MimeBodyPart();
    MimeBodyPart textContent = new MimeBodyPart();
    cover.addBodyPart(textContent);
    cover.addBodyPart(htmlContent);

    wrap.setContent(cover);

    MimeMultipart content = new MimeMultipart("related");
    content.addBodyPart(wrap);

    for (Attachment attachment : attachments) {
        ByteArrayDataSource dSource = new ByteArrayDataSource(Base64.decodeBase64(attachment.getBase64Image()),
                attachment.getMimeType());
        MimeBodyPart filePart = new MimeBodyPart();
        filePart.setDataHandler(new DataHandler(dSource));
        filePart.setFileName(attachment.getFileName());
        filePart.setHeader("Content-ID", "<" + attachment.getCid() + ">");
        filePart.setDisposition(MimeBodyPart.INLINE);
        content.addBodyPart(filePart);
    }

    htmlContent.setContent(html, "text/html; charset=UTF-8");
    textContent.setContent(
            "Twoj klient poczty nie wspiera formatu HTML/Your e-mail client doesn't support HTML format.",
            "text/plain; charset=UTF-8");

    msg.setContent(content);

    Transport.send(msg);
}
 
开发者ID:filipcynarski,项目名称:EMailSenderService,代码行数:63,代码来源:EmailMessage.java

示例13: send

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
	 * Mailテンプレートの内容を送信する。
	 * @param templ メール送信。
	 * @param session メールセッション。
	 * @throws Exception 例外。
	 */
	public void send(final MailTemplate templ, final Session session) throws Exception {
		String subject = templ.getMailSubject();
		log.debug("mail subject=" + subject);
		InternetAddress[] tolist = this.getAddressList(templ.getToList());
		InternetAddress[] cclist = this.getAddressList(templ.getCcList());
		InternetAddress[] bcclist = this.getAddressList(templ.getBccList());
		MimeMessage msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress(templ.getFrom(), templ.getFromPersonal(), "UTF-8"));
		InternetAddress[] replyTo = new InternetAddress[1];
		replyTo[0] = new InternetAddress(templ.getReplyTo());
		msg.setReplyTo(replyTo);
		msg.setRecipients(Message.RecipientType.TO, tolist);
		if (cclist != null) {
			msg.setRecipients(Message.RecipientType.CC, cclist);
		}
		if (bcclist != null) {
			msg.setRecipients(Message.RecipientType.BCC, bcclist);
		}
//		msg.setSubject(subject, "ISO-2022-JP");
		msg.setSubject(subject, "UTF-8");

		// mixed
		Multipart mixedPart = new MimeMultipart("mixed");

		// alternative
		MimeBodyPart alternativeBodyPart = new MimeBodyPart();
		MimeMultipart alternativePart = new MimeMultipart("alternative");
		alternativeBodyPart.setContent(alternativePart);
		mixedPart.addBodyPart(alternativeBodyPart);

		// text mail
		MimeBodyPart textBodyPart = new MimeBodyPart();
//		textBodyPart.setText(templ.getMailTextBody(), "ISO-2022-JP", "plain");
		textBodyPart.setText(templ.getMailTextBody(), "UTF-8", "plain");
		textBodyPart.setHeader("Content-Transfer-Encoding", "base64");
		alternativePart.addBodyPart(textBodyPart);	// alter

		// related
		MimeBodyPart relatedBodyPart = new MimeBodyPart();
		Multipart relatedPart = new MimeMultipart("related");
		relatedBodyPart.setContent(relatedPart);
		alternativePart.addBodyPart(relatedBodyPart);

		// html mail
		MimeBodyPart htmlBodyPart = new MimeBodyPart();
//		htmlBodyPart.setText(templ.getMailHtmlBody(), "ISO-2022-JP", "html");
		htmlBodyPart.setText(templ.getMailHtmlBody(), "UTF-8", "html");
		htmlBodyPart.setHeader("Content-Transfer-Encoding", "base64");
		relatedPart.addBodyPart(htmlBodyPart);

		// attach file
		for (MailTemplate.AttachFileInfo finfo: templ.getAttachFileList()) {
			MimeBodyPart attachBodyPart = new MimeBodyPart();
			DataSource dataSource2 = new FileDataSource(finfo.getPath());
			DataHandler dataHandler2 = new DataHandler(dataSource2);
			attachBodyPart.setDataHandler(dataHandler2);
//			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "iso-2022-jp", "B"));
//			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "UTF-8", null));
			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "UTF-8", "B"));
			attachBodyPart.setDisposition("attachment");  // attachment 指定しておく
			mixedPart.addBodyPart(attachBodyPart);
		}
		msg.setContent(mixedPart);
		Transport.send(msg);
	}
 
开发者ID:takayanagi2087,项目名称:dataforms,代码行数:72,代码来源:MailSender.java

示例14: addInline

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:MimeMessageHelper.java


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