将文档转换为MHTML并通过电子邮件发送
Contents
[
Hide
]
Aspose.Words可以将任何文档转换为MHTML(Web存档)格式。 这使得Aspose.Words和Aspose.Email
一起使用很方便。 您可以将任何支持的格式(如DOC、OOXML或RTF)的预定义文档加载到Aspose.Words中,用数据填充它,将生成的文档保存为MHTML,然后使用Aspose.Email
通过电子邮件发送。
下面的代码示例演示如何将任何文档转换为MHTML并通过电子邮件发送:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Load the document | |
Document doc = new Document(dataDir + "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 for 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(dataDir + "Message Out.msg", SaveOptions.getDefaultMsg()); | |
// Send the message using Aspose.Email | |
SmtpClient client = new SmtpClient(); | |
client.setHost("your_smtp.com"); | |
client.send(message); |