在使用Java和MimeMessage发送之前,在默认邮件客户端中预览电子邮件 [英] Preview an email in default mail client before sending with Java and MimeMessage

查看:197
本文介绍了在使用Java和MimeMessage发送之前,在默认邮件客户端中预览电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将MimeMessage发送到默认电子邮件客户端,以便我可以在发送JavaMail之前预览它?



我在一家非常专业的公司工作,这是一个必须。

解决方案

如果总邮件大小很小而且纯文本可以调用 MimeMessage.saveChanges 然后调用所有get方法构建一个来自现有MimeMessage的URI 。然后使用用于启动电子邮件客户端的java.awt.Desktop.mail(URI)方法。



否则,您必须调用 MimeMessage.saveChanges 然后使用 MimeMessage.writeTo 将其保存到文件系统为'.eml'。然后用 java.awt.Desktop.open 启动电子邮件客户端。电子邮件客户端关闭后,您必须处理清理工作。



您还必须考虑留在文件系统上的电子邮件的安全隐患。 / p>

How can i send a MimeMessage to the default email client so i can preview it before sending in 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. Then use the java.awt.Desktop.mail(URI) method to launch email client.

Otherwise, you have to 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和MimeMessage发送之前,在默认邮件客户端中预览电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆