本文整理了Java中javax.mail.internet.MimeBodyPart.attachFile()
方法的一些代码示例,展示了MimeBodyPart.attachFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.attachFile()
方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:attachFile
[英]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 Part#ATTACHMENT.
[中]使用指定的文件提供此零件的数据。简单文件名用作此零件的文件名,文件中的数据用作此零件的数据。将为文件数据选择适当的编码。此零件的处置设置为零件#附件。
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* 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 name of the file to attach
* @exception IOException errors related to accessing the file
* @exception MessagingException message related errors
* @since JavaMail 1.4
*/
public void attachFile(String file) throws IOException, MessagingException {
File f = new File(file);
attachFile(f);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* 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 name of the file to attach
* @exception IOException errors related to accessing the file
* @exception MessagingException message related errors
* @since JavaMail 1.4
*/
public void attachFile(String file) throws IOException, MessagingException {
File f = new File(file);
attachFile(f);
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Use the specified file with the specified Content-Type and
* Content-Transfer-Encoding to provide the data for this part.
* If contentType or encoding are null, appropriate values will
* be chosen.
* 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 disposition of this part is set to
* {@link Part#ATTACHMENT Part.ATTACHMENT}.
*
* @param file the name of the file
* @param contentType the Content-Type, or null
* @param encoding the Content-Transfer-Encoding, or null
* @exception IOException errors related to accessing the file
* @exception MessagingException message related errors
* @since JavaMail 1.5
*/
public void attachFile(String file, String contentType, String encoding)
throws IOException, MessagingException {
attachFile(new File(file), contentType, encoding);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Use the specified file with the specified Content-Type and
* Content-Transfer-Encoding to provide the data for this part.
* If contentType or encoding are null, appropriate values will
* be chosen.
* 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 disposition of this part is set to
* {@link Part#ATTACHMENT Part.ATTACHMENT}.
*
* @param file the name of the file
* @param contentType the Content-Type, or null
* @param encoding the Content-Transfer-Encoding, or null
* @exception IOException errors related to accessing the file
* @exception MessagingException message related errors
* @since JavaMail 1.5
*/
public void attachFile(String file, String contentType, String encoding)
throws IOException, MessagingException {
attachFile(new File(file), contentType, encoding);
}
代码示例来源:origin: stackoverflow.com
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile("resources/teapot.jpg");
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec
/**
* Attach a file to this body part from a file name.
*
* @param file The source file name.
*
* @exception IOException
* @exception MessagingException
*/
public void attachFile(String file) throws IOException, MessagingException {
// just create a File object and attach.
attachFile(new File(file));
}
代码示例来源:origin: wenmingvs/LogReport
/**
* 添加附件
*
* @param filePath 附件路径
* @param fileName 附件名称
* @throws Exception
*/
public void addAttachment(String filePath, String fileName) throws Exception {
BodyPart messageBodyPart = new MimeBodyPart();
((MimeBodyPart) messageBodyPart).attachFile(filePath);
multipart.addBodyPart(messageBodyPart);
}
代码示例来源:origin: com.sun.mail/mailapi
/**
* 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 name of the file to attach
* @exception IOException errors related to accessing the file
* @exception MessagingException message related errors
* @since JavaMail 1.4
*/
public void attachFile(String file) throws IOException, MessagingException {
File f = new File(file);
attachFile(f);
}
代码示例来源:origin: stackoverflow.com
File f = new File(file);
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(f);
multipart.addBodyPart(attachmentPart);
代码示例来源:origin: stackoverflow.com
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(body, "text/plain");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// adds attachments
MimeBodyPart attachPart = new MimeBodyPart();
File file=new File("Z:/filename");
try {
attachPart.attachFile(file);
} catch (IOException ex) {
ex.printStackTrace();
}
multipart.addBodyPart(attachPart);
// sets the multi-part as e-mail's content
message.setContent(multipart);
代码示例来源:origin: stackoverflow.com
Multipart multipart = new MimeMultipart("mixed");
for (int alen = 0; attlen < attachments.length; attlen++)
{
MimeBodyPart messageAttachment = new MimeBodyPart();
fileName = ""+ attachments[attlen];
messageAttachment.attachFile(fileName);
messageAttachment.setFileName(attachment);
multipart.addBodyPart(messageAttachment);
}
代码示例来源:origin: stackoverflow.com
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(attachment);
attachmentPart.setHeader("Content-Type", "text/plain;charset=utf-8");
multipart.addBodyPart(attachmentPart);
代码示例来源:origin: stackoverflow.com
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
String message = "file attached. ";
messageBodyPart.setText(message, "utf-8", "html");
multipart.addBodyPart(messageBodyPart);
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.attachFile(new File(filePath+"/"+fileName), "application/pdf", null);
multipart.addBodyPart(attachmentBodyPart);
mail.setContent(multipart);
代码示例来源:origin: stackoverflow.com
MimeBodyPart mimeBody = new MimeBodyPart();
mimeBody.attachFile(file);
MimeMultipart mimeMulti = new MimeMultipart();
mimeMulti.addBodyPart(mimeBody);
msg.setContent(mimeMulti);
代码示例来源:origin: stackoverflow.com
String htmlFileName = "/home/vikki/Documents/MailTemplate.html";
MimeBodyPart part = new MimeBodyPart();
part.attachFile(htmlFileName);
part.setDisposition(Part.INLINE);
message.setContent(new MimeMultipart(part));
代码示例来源:origin: stackoverflow.com
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("coucou the file is here");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
messageBodyPart.attachFile(file);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
代码示例来源:origin: stackoverflow.com
// first part (the html)
MimeBodyPart messageBodyPart = new MimeBodyPart();
String htmlText = "<H1>This is the image: </H1><img src=\"cid:image\">";
messageBodyPart.setText(htmlText, null, "html");
multipart.addBodyPart(messageBodyPart);
// second part (the image)
messageBodyPart = new MimeBodyPart();
String filePath = "C:/image.png";
messageBodyPart.attachFile(filePath, "image/png", "base64");
messageBodyPart.setContentID("<image>");
// add image to the multipart
multipart.addBodyPart(messageBodyPart);
代码示例来源:origin: stackoverflow.com
MimeMultipart mp = new MimeMultipart();
MimeBodyPart body = new MimeBodyPart();
body.setText(allLines_html, "iso-8859-1", "html");
mp.addBodyPart(body);
MimeBodyPart attachPart = new MimeBodyPart();
File attachement = new File("E:\\car_failed_report\\failed.xls");
if (attachement.exists()) {
attachPart.attachFile(attachement);
mp.addBodyPart(attachPart);
} else {
System.out.println("ERROR READING THE FILE");
throw new FileNotFoundException();
}
message.setContent(mp);
代码示例来源:origin: stackoverflow.com
Message message = new MimeMessage(session);
message.setFrom(""); // hopefully you're putting a real value here
message.setRecipients(""); // and here
message.setSubject("Test");
MimeBodyPart attachment = new MimeBodyPart();
Multipart mp1 = new MimeMultipart();
attachment.attachFile("sample.pdf", "application/pdf", "base64");
mp1.addBodyPart(attachment);
message.setContent(mp1);
Transport.send(message);
代码示例来源:origin: stackoverflow.com
MimeBodyPart imgBodyPart = new MimeBodyPart();
imgBodyPart.attachFile("Image.png");
imgBodyPart.setContentID('<'+"i01@example.com"+'>');
imgBodyPart.setDisposition(MimeBodyPart.INLINE);
imgBodyPart.setHeader("Content-Type", "image/png");
multipart.addBodyPart(imgBodyPart);
内容来源于网络,如有侵权,请联系作者删除!