发送电子邮件附件使用byte []与Java-Mail [英] Send Email Attachement using byte[] with Java-Mail
问题描述
我有一个字节数组,我希望作为附件添加到我发送的电子邮件。
I have a byte array wich i wish to add as an attachement to an email i am sending.
不幸的是,我找不到如何附加它作为字节数组,解决方案我使用磁盘文件(我不想要,因为我不想写字节数组,所以我可以附加它)。
Unfortunally i can't find how to attach it as a byte array, the solution i have uses disk files (which i dont want since i dont want to write the byte array just so i can attach it).
我有发现一个解决方案涉及创建扩展DataSource的对象,并将其用作字节数组的包装器,然后将其提供给MimeBodyPart。
I've found one solution that involves creating an object that extends DataSource and use this as a wrapper for the byte array and then feed that to the MimeBodyPart.
任何人都知道更好的解决方案?
Anyone know of a better solution?
推荐答案
创建一个 DataSource
是正确的方法。你不必写自己的,但是。只需使用 ByteArrayDataSource
来自JavaMail。
Creating a DataSource
is the right approach. You don't have to write your own, though. Just use the ByteArrayDataSource
from JavaMail.
这篇关于发送电子邮件附件使用byte []与Java-Mail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!