如何使用Java打开草稿中的邮件并将文件附加到邮件 [英] how to open mail in draft and attach file to mail using java
问题描述
我试图使用邮件发送文件,但我想首先在草稿邮件(如jsp中的mailto)中打开它.我已经在Java中实现了邮件到功能的实现,但是无法将文件附加到打开的邮件中. 除附件外,其他均为工作文件. 这是我的代码:
I was trying to send a file using mail but I wanted to first it open in a draft mail like mailto in jsp. I had implemented mail to functionality in Java but I am not able to attach file to opened mail. other are working file except the attachment. here is my code:
public static void mailto(List<String> recipients, String subject,
String body) throws IOException, URISyntaxException {
String uriStr = String.format("mailto:%s?subject=%s&body=%s",
recipients,subject,body);
Desktop.getDesktop().browse(new URI(uriStr));
}
有人可以建议我如何使用mailto或任何其他对我有用的api附加文件.enter code here
can any one suggest me how to attach file using mailto or any other api that can useful for me.enter code here
提前谢谢.
推荐答案
创建使用JavaMail的分段MimeMessage ,但将其发送 调用 MimeMessage.saveChanges 然后使用 MimeMessage .writeTo 将其保存为".eml"到文件系统.然后使用
Create Multipart MimeMessage using JavaMail but instead sending it call MimeMessage.saveChanges then use MimeMessage.writeTo to save it to the filesystem as '.eml'. Then open that file with java.awt.Desktop.open to launch the email client. You'll have to handle clean up after the email client is closed.
您还必须考虑将电子邮件保留在文件系统上的安全隐患.
You also have to think about the security implications of email messages being left on the file system.
这篇关于如何使用Java打开草稿中的邮件并将文件附加到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!