להפוך מסמך ל- MHTML ו- Send באמצעות דואר אלקטרוני
Aspose.Words ניתן להמיר כל מסמך לתבנית MHTML (ארכיון אינטרנט) זה הופך את זה נוח לשימוש Aspose.Words ו Aspose.Email
יחד. ניתן לטעון מסמך מוגדר מראש בכל פורמט נתמך, כגון DOC, OOXML, או RTF, לתוך Aspose.Wordsלמלא אותו בנתונים, שמור את המסמך המתקבל כ- MHTML ולאחר מכן שלח אותו בדואר אלקטרוני באמצעות דואר אלקטרוני. Aspose.Email
.
הדוגמה הבאה של הקוד מראה כיצד להמיר כל מסמך ל- MHTML ולשלוח אותו בדואר אלקטרוני:
// 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); |