문서를MHTML으로 변환하고 이메일로 보냅니다
Contents
[
Hide
]
Aspose.Words모든 문서를MHTML(웹 아카이브)형식으로 변환할 수 있습니다. 따라서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); |