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


Java MimeBodyPart.setContent方法代码示例

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


在下文中一共展示了MimeBodyPart.setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: buildEmailBodyPart

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

    // add from low fidelity to high fidelity
    if (StringUtils.isNotBlank(text)) {
        final MimeBodyPart textBodyPart = buildTextBodyPart();
        emailContent.addBodyPart(textBodyPart);
    }

    if (StringUtils.isNotBlank(html)) {
        final MimeBodyPart htmlBodyPart = buildHtmlBodyPart();
        emailContent.addBodyPart(htmlBodyPart);
    }

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

示例3: createMimeMessageWithHtml

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public static MimeMessage createMimeMessageWithHtml(Session session) throws MessagingException, AddressException {
  MimeMessage message = createMimeMessage(session);

  Multipart multiPart = new MimeMultipart();

  MimeBodyPart textPart = new MimeBodyPart();
  textPart.setText("text");
  multiPart.addBodyPart(textPart);

  MimeBodyPart htmlPart = new MimeBodyPart();
  htmlPart.setContent("<b>html</b>", MailContentType.TEXT_HTML.getType());
  multiPart.addBodyPart(htmlPart);

  message.setContent(multiPart);
  return message;
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:17,代码来源:MailTestUtil.java

示例4: send

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * 发送邮件
 * @param receiver 接收者邮箱地址
 * @param subject 邮件主题
 * @param content 邮件内容
 */
public static void send(String receiver, String subject, String content) {
    try {
        //设置SSL连接、邮件环境
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
        Properties props = System.getProperties();
        props.setProperty("mail.smtp.host", SMTP_HOST);
        props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", SMTP_PORT);
        props.setProperty("mail.smtp.socketFactory.port", SMTP_SOCKET_FACTORY_PORT);
        props.setProperty("mail.smtp.auth", "true");
        //建立邮件会话
        Session session = Session.getDefaultInstance(props, new Authenticator() {
            //身份认证
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(SENDER, PASSWORD);
            }
        });
        //建立邮件对象
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(SENDER, SENDER_NAME));
        message.setRecipients(Message.RecipientType.TO, receiver);
        message.setSubject(subject);

        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setContent(content, "text/html;charset=UTF-8");
        MimeMultipart mimeMultipart = new MimeMultipart();
        mimeMultipart.addBodyPart(mimeBodyPart);

        message.setContent(mimeMultipart);
        message.saveChanges();

        Transport.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:jthinking,项目名称:linux-memory-monitor,代码行数:45,代码来源:JavaMail.java

示例5: addAlternativePart

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

示例6: 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

示例7: createMimeMultiparts

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Determine the MimeMultipart objects to use, which will be used
 * to store attachments on the one hand and text(s) and inline elements
 * on the other hand.
 * <p>Texts and inline elements can either be stored in the root element
 * itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED) or in a nested element
 * rather than the root element directly (MULTIPART_MODE_MIXED_RELATED).
 * <p>By default, the root MimeMultipart element will be of type "mixed"
 * (MULTIPART_MODE_MIXED) or "related" (MULTIPART_MODE_RELATED).
 * The main multipart element will either be added as nested element of
 * type "related" (MULTIPART_MODE_MIXED_RELATED) or be identical to the root
 * element itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED).
 * @param mimeMessage the MimeMessage object to add the root MimeMultipart
 * object to
 * @param multipartMode the multipart mode, as passed into the constructor
 * (MIXED, RELATED, MIXED_RELATED, or NO)
 * @throws MessagingException if multipart creation failed
 * @see #setMimeMultiparts
 * @see #MULTIPART_MODE_NO
 * @see #MULTIPART_MODE_MIXED
 * @see #MULTIPART_MODE_RELATED
 * @see #MULTIPART_MODE_MIXED_RELATED
 */
protected void createMimeMultiparts(MimeMessage mimeMessage, int multipartMode) throws MessagingException {
	switch (multipartMode) {
		case MULTIPART_MODE_NO:
			setMimeMultiparts(null, null);
			break;
		case MULTIPART_MODE_MIXED:
			MimeMultipart mixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
			mimeMessage.setContent(mixedMultipart);
			setMimeMultiparts(mixedMultipart, mixedMultipart);
			break;
		case MULTIPART_MODE_RELATED:
			MimeMultipart relatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
			mimeMessage.setContent(relatedMultipart);
			setMimeMultiparts(relatedMultipart, relatedMultipart);
			break;
		case MULTIPART_MODE_MIXED_RELATED:
			MimeMultipart rootMixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
			mimeMessage.setContent(rootMixedMultipart);
			MimeMultipart nestedRelatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
			MimeBodyPart relatedBodyPart = new MimeBodyPart();
			relatedBodyPart.setContent(nestedRelatedMultipart);
			rootMixedMultipart.addBodyPart(relatedBodyPart);
			setMimeMultiparts(rootMixedMultipart, nestedRelatedMultipart);
			break;
		default:
			throw new IllegalArgumentException("Only multipart modes MIXED_RELATED, RELATED and NO supported");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:MimeMessageHelper.java

示例8: addFile

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public MailSender addFile(File file) throws Exception {
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setContent(body, "text/html");
    multipart.addBodyPart(mbp1);
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(file);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    multipart.addBodyPart(mbp2);
    return this;
}
 
开发者ID:KursX,项目名称:Parallator,代码行数:12,代码来源:MailSender.java

示例9: createAttachMail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
  * @Method: createAttachMail
  * @Description: ����һ����������ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createAttachMail(String subject, String content, String filePath) throws Exception{
      MimeMessage message = new MimeMessage(session);
      
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(attach);
      mp.setSubType("mixed");
      
      message.setContent(mp);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:41,代码来源:EmailUtil.java

示例10: createImageMail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
  * @Method: createImageMail
  * @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {

      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      MimeBodyPart image = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(imagePath));
      image.setDataHandler(dh);
      image.setContentID("xxx.jpg");
      MimeMultipart mm = new MimeMultipart();
      mm.addBodyPart(text);
      mm.addBodyPart(image);
      mm.setSubType("related");

      message.setContent(mm);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:39,代码来源:EmailUtil.java

示例11: createMixedMail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
  * @Method: createMixedMail
  * @Description: ����һ��������ʹ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content,"text/html;charset=UTF-8");
      
      MimeBodyPart image = new MimeBodyPart();
      image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
      image.setContentID("aaa.jpg");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(image);
      mp.setSubType("related");
      
      MimeBodyPart bodyContent = new MimeBodyPart();
      bodyContent.setContent(mp);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:46,代码来源:EmailUtil.java

示例12: sendTextEmail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public static void sendTextEmail(String recvEmail) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject("Hello Vme");
		//整个邮件的MultiPart(不能直接加入内容,需要在bodyPart中加入)
		Multipart emailPart = new MimeMultipart();
		MimeBodyPart attr1 = new MimeBodyPart();
		attr1.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/2601169057.png")));
		attr1.setFileName("tip.pic");
		
		MimeBodyPart attr2 = new MimeBodyPart();
		attr2.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		attr2.setFileName(MimeUtility.encodeText("哦图像"));
		
		MimeBodyPart content = new MimeBodyPart();
		MimeMultipart contentPart = new MimeMultipart();
		
		MimeBodyPart imgPart = new MimeBodyPart();
		imgPart.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		imgPart.setContentID("pic");
		
		MimeBodyPart htmlPart = new MimeBodyPart();
		htmlPart.setContent("<h1><a href='www.baidu.com'>百度一下</a><img src='cid:pic'/></h1>", "text/html;charset=utf-8");
		
		contentPart.addBodyPart(imgPart);
		contentPart.addBodyPart(htmlPart);
		content.setContent(contentPart);
		
		emailPart.addBodyPart(attr1);
		emailPart.addBodyPart(attr2);
		emailPart.addBodyPart(content);
		msg.setContent(emailPart);
		
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse("[email protected],[email protected]"));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:55,代码来源:EmailHelper.java

示例13: makeEmail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private MimeMessage makeEmail(TokenData data, _EmailTemplate template, List<_BridgeMessageContent> contents, boolean allowReply) throws MessagingException, IOException {
    MimeMultipart body = new MimeMultipart();
    body.setSubType("alternative");

    for (_BridgeMessageContent content : contents) {
        MimeMultipart contentBody = new MimeMultipart();
        contentBody.setSubType("related");

        Optional<_EmailTemplateContent> contentTemplateOpt = template.getContent(content.getMime());
        if (!contentTemplateOpt.isPresent()) {
            continue;
        }

        _EmailTemplateContent contentTemplate = contentTemplateOpt.get();
        contentBody.addBodyPart(makeBodyPart(data, contentTemplate, content));

        if (contentTemplate.getContent().contains(EmailTemplateToken.SenderAvatar.getToken()) &&
                data.getSenderAvatar() != null && data.getSenderAvatar().isValid()) {
            log.info("Adding avatar for sender");

            MimeBodyPart avatarBp = new MimeBodyPart();
            _MatrixContent avatar = data.getSenderAvatar();
            String filename = avatar.getFilename().orElse("unknown." + avatar.getType().replace("image/", ""));

            avatarBp.setContent(avatar.getData(), avatar.getType());
            avatarBp.setContentID("<" + senderAvatarId + ">");
            avatarBp.setDisposition("inline; filename=" + filename + "; size=" + avatar.getData().length + ";");

            contentBody.addBodyPart(avatarBp);
        }

        MimeBodyPart part = new MimeBodyPart();
        part.setContent(contentBody);

        body.addBodyPart(part);
    }

    return makeEmail(data, template, body, allowReply);
}
 
开发者ID:kamax-io,项目名称:matrix-appservice-email,代码行数:40,代码来源:EmailFormatterOutboud.java

示例14: create

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public MimeMessage create(final IMail mail) throws CreationException {
  try {
    final MimeMessage mimeMessage = new MimeMessage(this.session);
    mimeMessage.setFrom(new InternetAddress(mail.getSender()));
    if (mail.getReplayRecipient() != null) {
      mimeMessage.setReplyTo(new Address[]{ new InternetAddress(mail.getReplayRecipient()) });
    }
    mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(mail.getRecipient(), false));
    mimeMessage.setSubject(mail.getSubject());
    final Multipart multiPart = new MimeMultipart();
    final BodyPart messageBody = new MimeBodyPart();
    messageBody.setText(mail.getContent());
    multiPart.addBodyPart(messageBody);
    for (final Attachment attachment : mail.getAttachments()) {
      final MimeBodyPart attachmentPart = new MimeBodyPart();
      attachmentPart.setFileName(attachment.getFilename());
      attachmentPart.setContent(
          attachment.getContent() == null ? "--empty--" : attachment.getContent(), //$NON-NLS-1$
          attachment.getMimeTpye());
      multiPart.addBodyPart(attachmentPart);
    }
    mimeMessage.setContent(multiPart);
    mimeMessage.setSentDate(new Date());
    return mimeMessage;
  } catch (final MessagingException exception) {
    throw new CreationException(exception.getMessage(), exception);
  }
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:29,代码来源:MimeMessageFactory.java

示例15: 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


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