简体   繁体   English

在使用 Java 和 MimeMessage 发送之前在默认邮件客户端中预览电子邮件

[英]Preview an email in default mail client before sending with Java and MimeMessage

How can i send a MimeMessage to the default email client so i can preview it before sending in JavaMail?我如何将 MimeMessage 发送到默认电子邮件客户端,以便在发送 JavaMail 之前预览它?

I work at a very burocratic company and this is a MUST.我在一家非常官僚的公司工作,这是必须的。

If the total message size is small and plain text you can call MimeMessage.saveChanges then call all of the get methods build a URI from the existing MimeMessage .如果总消息大小很小并且是纯文本,您可以调用MimeMessage.saveChanges然后调用所有 get 方法从现有的 MimeMessage构建一个URI Then use the java.awt.Desktop.mail(URI) method to launch email client.然后使用java.awt.Desktop.mail(URI)方法启动电子邮件客户端。

Otherwise, you have to call MimeMessage.saveChanges then use MimeMessage.writeTo to save it to the filesystem as '.eml'.否则,您必须调用MimeMessage.saveChanges,然后使用MimeMessage.writeTo将其作为“.eml”保存到文件系统。 Then open that file with java.awt.Desktop.open to launch the email client.然后使用java.awt.Desktop.open打开该文件以启动电子邮件客户端。 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.您还必须考虑留在文件系统上的电子邮件消息的安全隐患。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM