文書を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); |