Java Mail API发送附加了其他邮件的邮件

时间:2011-09-02 12:52:56

标签: java email attachment send

我想问一下如何通过附件邮件发送带有Java Mail API的消息。

MimeBodyPart attachmentPart = new MimeBodyPart ( );
attachmentPart.setContent ( mail , "text/?" );

提前致谢!

1 个答案:

答案 0 :(得分:2)

javax.mail.Multipart multipart = new MimeMultipart();

javax.mail.internet.MimeBodyPart messageBodyPart =   new  javax.mail.internet.MimeBodyPart();

multipart.addBodyPart(messageBodyPart);

javax.activation.DataSource source = new FileDataSource("C:\\Notes\\new mail.msg");

messageBodyPart.setDataHandler( new DataHandler(source));
messageBodyPart.setFileName("new mail.msg");

multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);

 MimeBodyPart part = new MimeBodyPart();
 part.setText(text);

multipart.addBodyPart(part);