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


Java MimeBodyPart.setDescription方法代碼示例

本文整理匯總了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;
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:10,代碼來源:Mail.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-greenmail,代碼行數:45,代碼來源:GreenMailUtil.java


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