當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeBodyPart.setFileName方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeBodyPart.setFileName方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeBodyPart.setFileName方法的具體用法?Java MimeBodyPart.setFileName怎麽用?Java MimeBodyPart.setFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeBodyPart的用法示例。


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

示例4: addAttachFile

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * 
 * 發送郵件時添加附件列表
 * @param mp
 * @param attachFiles
 * @return
 * @throws MailException
 * @throws IOException
 * @throws MessagingException
 */
private Multipart  addAttachFile(Multipart mp, Set<String> attachFiles) throws MailException, IOException, MessagingException{
	
	if(mp == null){
		throw new MailException("bean Multipart is null .");
	}
	
	//沒有附件時直接返回
	if(attachFiles == null || (attachFiles.size())== 0){
		return mp;
	}
	Iterator<String> iterator = attachFiles.iterator();
	while (iterator.hasNext()) {
		String fileName  = iterator.next();
		MimeBodyPart mbp_file = new MimeBodyPart();
		mbp_file.attachFile(fileName);
		mp.addBodyPart(mbp_file);
		//防止亂碼
		String encode = MimeUtility.encodeText(mbp_file.getFileName());
           mbp_file.setFileName(encode); 
		
	}
	
	return mp;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:35,代碼來源:MailServiceImpl.java

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

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

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

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

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

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

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

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

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

示例14: createEmailWithAttachment

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static MimeMessage createEmailWithAttachment(String to, String from, String subject,
                                      String bodyText,String filePath) throws MessagingException{
    File file = new File(filePath);
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage email = new MimeMessage(session);
    Multipart multipart = new MimeMultipart();
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);
    email.setFrom(fAddress);
    email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
    email.setSubject(subject);
    if (file.exists()) {
        source = new FileDataSource(filePath);
        messageFilePart = new MimeBodyPart();
        messageBodyPart = new MimeBodyPart();
        try {
            messageBodyPart.setText(bodyText);
            messageFilePart.setDataHandler(new DataHandler(source));
            messageFilePart.setFileName(file.getName());

            multipart.addBodyPart(messageBodyPart);
            multipart.addBodyPart(messageFilePart);
            email.setContent(multipart);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }else
        email.setText(bodyText);
    return email;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:32,代碼來源:EmailShield.java

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


注:本文中的javax.mail.internet.MimeBodyPart.setFileName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。