- 在电子邮件正文中发送Word文档
为了在电子邮件正文中导入和发送Word文档,我们将利用Aspose.Words for Java和Aspose.Email for Java前者将用于以MHTML格式保存Word文档,而后者将用于创建和发送电子邮件。如果想要测试这项新功能,可下载Aspose.Words for Java和Aspose.Email for Java最新版试用。
整合所有格式的Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部咨询!
使用Java在电子邮件正文中发送Word文档
以下是在电子邮件正文中导入和发送Word文档的步骤。
- 使用com.aspose.words.Document类加载Word文档。
- 创建一个ByteArrayOutputStream类的实例。
- 将Word文档作为MHTML保存在ByteArrayOutputStream对象中。
- 在ByteArrayInputStream对象中加载MHTML。
- 创建com.aspose.email.MailMessage类的实例并加载保存在ByteArrayInputStream对象中的MHTML。
- 设置电子邮件的字段,如收件人、发件人、主题等。
- 创建com.aspose.email.SmtpClient类的一个实例
- 设置主机并使用SmtpClient.send(MailMessage)方法发送邮件。
下面的代码示例演示如何将Word文档作为电子邮件正文发送。
// Load the documentDocument doc = new Document("Document.doc");// Save to an output stream in MHTML format.ByteArrayOutputStream outputStream = new ByteArrayOutputStream();doc.save(outputStream, SaveFormat.MHTML);// Load the MHTML stream back into an input stream to use with Aspose.Email.ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());// Create an Aspose.Email MIME email message from the stream.MailMessage message = MailMessage.load(inputStream);message.setFrom(new MailAddress("your_from@email.com"));message.getTo().add("your_to@email.com");message.setSubject("Aspose.Words + Aspose.Email MHTML Test Message");// Save the message in Outlook MSG format.message.save("Message.msg", SaveOptions.getDefaultMsg());// Send the message using Aspose.EmailSmtpClient client = new SmtpClient();client.setHost("your_smtp.com");client.send(message);
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【Aspose最新资源在线文库】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!