本文整理汇总了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 "";
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}