本文整理匯總了Java中javax.mail.internet.MimeBodyPart.setDescription方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeBodyPart.setDescription方法的具體用法?Java MimeBodyPart.setDescription怎麽用?Java MimeBodyPart.setDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeBodyPart
的用法示例。
在下文中一共展示了MimeBodyPart.setDescription方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: sendAttachmentEmail
import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static void sendAttachmentEmail(String to, String from, String subject, String msg, final byte[] attachment, final String contentType, final String filename, final String description, final ServerSetup setup) throws MessagingException, IOException {
Session session = getSession(setup);
Address[] tos = new InternetAddress[]{new InternetAddress(to)};
Address[] froms = new InternetAddress[]{new InternetAddress(from)};
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setSubject(subject);
mimeMessage.setFrom(froms[0]);
MimeMultipart multiPart = new MimeMultipart();
MimeBodyPart textPart = new MimeBodyPart();
multiPart.addBodyPart(textPart);
textPart.setText(msg);
MimeBodyPart binaryPart = new MimeBodyPart();
multiPart.addBodyPart(binaryPart);
DataSource ds = new DataSource() {
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(attachment);
}
public OutputStream getOutputStream() throws IOException {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byteStream.write(attachment);
return byteStream;
}
public String getContentType() {
return contentType;
}
public String getName() {
return filename;
}
};
binaryPart.setDataHandler(new DataHandler(ds));
binaryPart.setFileName(filename);
binaryPart.setDescription(description);
mimeMessage.setContent(multiPart);
Transport.send(mimeMessage, tos);
}