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


Java MimeBodyPart.setDataHandler方法代码示例

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


在下文中一共展示了MimeBodyPart.setDataHandler方法的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: addAttachment

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

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

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

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

示例6: createMultiPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * 创建复杂的正文
 * @return
 * @throws MessagingException 
 */
private Multipart createMultiPart() throws MessagingException {
	// TODO Auto-generated method stub
	Multipart multipart=new MimeMultipart();
	
	//第一块
	BodyPart bodyPart1=new MimeBodyPart();
	bodyPart1.setText("创建复杂的邮件,此为正文部分");
	multipart.addBodyPart(bodyPart1);
	
	//第二块 以附件形式存在
	MimeBodyPart bodyPart2=new MimeBodyPart();
	//设置附件的处理器
	FileDataSource attachFile=new FileDataSource(ClassLoader.getSystemResource("attach.txt").getFile());
	DataHandler dh=new DataHandler(attachFile);
	bodyPart2.setDataHandler(dh);
	bodyPart2.setDisposition(Part.ATTACHMENT);
	bodyPart2.setFileName("test");
	multipart.addBodyPart(bodyPart2);
	
	return multipart;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:27,代码来源:SimpleSendReceiveMessage.java

示例7: createAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private MimeBodyPart createAttachment(File file, String filename, String desc) throws IOException, MessagingException {
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.attachFile(file);
    FileDataSource fds = new FileDataSource(file);
    mbp.setDataHandler(new DataHandler(fds));
    mbp.setDescription(desc);
    mbp.setFileName(MimeUtility.encodeText(filename));
    return mbp;
}
 
开发者ID:TFdream,项目名称:okmail,代码行数:10,代码来源:Mail.java

示例8: addAttachmentDir

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Appends all files in a specified folder as attachments
 *
 * @param folder the folder containing all files to be attached
 * @throws PackageException
 */
@PublicAtsApi
public void addAttachmentDir(
                              String folder ) throws PackageException {

    // fetch list of files in specified directory
    File dir = new File(folder);
    File[] list = dir.listFiles();
    if (null == list) {
        throw new PackageException("Could not read from directory '" + folder + "'.");
    } else {
        // process all files, skipping directories
        for (int i = 0; i < list.length; i++) {
            if ( (null != list[i]) && (!list[i].isDirectory())) {
                // add attachment to multipart content
                MimeBodyPart attPart = new MimeBodyPart();
                FileDataSource ds = new FileDataSource(list[i].getPath());

                try {
                    attPart.setDataHandler(new DataHandler(ds));
                    attPart.setDisposition(MimeBodyPart.ATTACHMENT);
                    attPart.setFileName(ds.getName());
                } catch (MessagingException me) {
                    throw new PackageException(me);
                }

                addPart(attPart, PART_POSITION_LAST);
            }
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:37,代码来源:MimePackage.java

示例9: addAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void addAttachment(Multipart mp, byte[] attachmentData, String mimeType, String filename)
    throws MessagingException {
  if (mp == null) {
    return;
  }
  ByteArrayDataSource dataSrc = new ByteArrayDataSource(attachmentData, mimeType);
  MimeBodyPart attachment = new MimeBodyPart();
  attachment.setFileName(filename);
  attachment.setDataHandler(new DataHandler(dataSrc));
  ///attachment.setContent( attachmentData, mimeType );
  mp.addBodyPart(attachment);
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:13,代码来源:EmailService.java

示例10: addAttachmentStream

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void addAttachmentStream(Multipart mp, InputStream attachmentStream, String mimeType,
                                 String filename, BodyPart message)
    throws MessagingException, IOException {
  if (mp == null) {
    return;
  }
  ByteArrayDataSource dataSrc = new ByteArrayDataSource(attachmentStream, mimeType);
  MimeBodyPart attachment = new MimeBodyPart();
  attachment.setFileName(filename);
  attachment.setDataHandler(new DataHandler(dataSrc));
  ///attachment.setContent( attachmentData, mimeType );
  mp.addBodyPart(message);
  mp.addBodyPart(attachment);
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:15,代码来源:EmailService.java

示例11: addAttachment

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

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

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

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

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


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