files.setFileName( fds.getName() );
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }
String filename = MimeUtility.encodeText(fds.getName());
public String getName() { if (fileName != null) { return fileName; } else { return super.getName(); } }
public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); }
/** * Attach a file to this body part from a File object. * * @param file The source File object. * * @exception IOException * @exception MessagingException */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource dataSource = new FileDataSource(file); setDataHandler(new DataHandler(dataSource)); setFileName(dataSource.getName()); }
MimeMessage message = new MimeMessage(session); message.setSender(new InternetAddress(sender)); message.setSubject(subject); MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body); MimeBodyPart mbp2 = new MimeBodyPart(); FileDataSource fds = new FileDataSource(attachment); //set attachment to filedatasource mbp2.setDataHandler(new DataHandler(fds)); //add the filedatasource object to your 2nd mimebodypart mbp2.setFileName(fds.getName()); Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); message.setContent(mp); ...send email...
Multipart mp = new MimeMultipart(); MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(body,"text/html"); mp.addBodyPart(mbp1); if(filename!=null) { MimeBodyPart mbp2 = null; FileDataSource fds =null; for(int counter=0;counter<filename.length;counter++) { mbp2 = null; fds =null; mbp2=new MimeBodyPart(); fds = new FileDataSource(filename[counter]); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); mp.addBodyPart(mbp2); } } msg.setContent(mp); msg.setSentDate(new Date()); Transport.send(msg);
private MimeBodyPart createAttachment(File file, String fileName) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); FileDataSource fds = new FileDataSource(file); attachmentPart.setDataHandler(new DataHandler(fds)); try { attachmentPart.setFileName(null == fileName ? MimeUtility.encodeText(fds.getName()) : MimeUtility.encodeText(fileName)); } catch (Exception e) { e.printStackTrace(); } return attachmentPart; }
public void addAttachMent(String filename){ try{ BodyPart bp = new MimeBodyPart(); FileDataSource fileds = new FileDataSource(filename); bp.setDataHandler(new DataHandler(fileds)); bp.setFileName(MimeUtility.encodeWord(fileds.getName())); mp.addBodyPart(bp); }catch(Exception e){ logger.error(e); } }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); }
// Set a file as an attachment public static void setFileAsAttachment(Message msg, String filename) throws MessagingException { // Create and fill first part MimeBodyPart p1 = new MimeBodyPart(); p1.setText("This is part one of a test multipart e-mail." + "The second part is file as an attachment"); // Create second part MimeBodyPart p2 = new MimeBodyPart(); // Put a file in the second part FileDataSource fds = new FileDataSource(filename); p2.setDataHandler(new DataHandler(fds)); p2.setFileName(fds.getName()); // Create the Multipart. Add BodyParts to it. Multipart mp = new MimeMultipart(); mp.addBodyPart(p1); mp.addBodyPart(p2); // Set Multipart as the message's content msg.setContent(mp); }
/** * 设置附件 * * @param name String * @param pass String */ public boolean addFileAffix(String filename) { logger.info(Resources.getMessage("EMAIL.ADD_ATTEND"), filename); try { BodyPart bp = new MimeBodyPart(); FileDataSource fileds = new FileDataSource(filename); bp.setDataHandler(new DataHandler(fileds)); bp.setFileName(MimeUtility.encodeText(fileds.getName())); mp.addBodyPart(bp); return true; } catch (Exception e) { logger.error(filename, e); return false; } }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }
private MimeBodyPart createAttachment(File file, String fileName) throws SendMailException { MimeBodyPart attachmentPart = new MimeBodyPart(); FileDataSource fds = new FileDataSource(file); try { attachmentPart.setDataHandler(new DataHandler(fds)); attachmentPart.setFileName(null == fileName ? MimeUtility.encodeText(fds.getName()) : MimeUtility.encodeText(fileName)); } catch (Exception e) { throw new SendMailException(e); } return attachmentPart; }
/** * Use the specified file to provide the data for this part. * The simple file name is used as the file name for this * part and the data in the file is used as the data for this * part. The encoding will be chosen appropriately for the * file data. The disposition of this part is set to * {@link Part#ATTACHMENT Part.ATTACHMENT}. * * @param file the File object to attach * @exception IOException errors related to accessing the file * @exception MessagingException message related errors * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileDataSource fds = new FileDataSource(file); this.setDataHandler(new DataHandler(fds)); this.setFileName(fds.getName()); this.setDisposition(ATTACHMENT); }