我想问一下如何通过附件邮件发送带有Java Mail API的消息。
MimeBodyPart attachmentPart = new MimeBodyPart ( );
attachmentPart.setContent ( mail , "text/?" );
提前致谢!
答案 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);