我正在使用javamail API创建电子邮件并将文件附加到它.
有没有办法使用javamail api发送带附件的电子邮件,而无需在文件系统上物理创建文件.
我只想从应用程序中选择一些数据并将其作为文件附加到我的电子邮件中
我该如何附上:
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
**mbp2.attachFile(filename);**
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the …Run Code Online (Sandbox Code Playgroud)