Outlook संदेश (MSG) फ़ाइल बनाना
हमारी माइग्रेशन टिप्स दर्शाती हैं कि Aspose उत्पादों का उपयोग कैसे आपके अनुप्रयोगों को सुधारने और पारंपरिक ऑटोमेशन पर निर्भरता से मुक्त करने के लिए किया जा सकता है।
यह माइग्रेशन टिप दिखाती है कि Outlook संदेश (MSG) फ़ाइल कैसे बनाएं उपयोग करके Microsoft Office ऑटोमेशन और Aspose.Email. कोड नमूने MSG फ़ाइल की मूल प्रॉपर्टीज़ - To, Cc, Subject, और HTML बॉडी - सेट करते हैं, फिर फ़ाइल को डिस्क पर सहेजते हैं।
Office Automation
Office Automation का उपयोग करने के लिए, कोड चलने वाली मशीन पर Microsoft Outlook स्थापित होना चाहिए। Outlook.interop.dll का रेफ़रेंस भी आवश्यक है।
प्रोग्रामिंग नमूने
निम्नलिखित कोड स्निपेट्स Office Automation का उपयोग करके MSG फ़ाइल बनाते हैं।
C#
// Creates a new Outlook Application instance
Outlook.Application objOutlook = new Outlook.Application();
// Creating a new Outlook message from the Outlook Application instance
Outlook.MailItem msgInterop = (Outlook.MailItem)(objOutlook.CreateItem(Outlook.OlItemType.olMailItem));
// Set recipient information
msgInterop.To = "to@domain.com";
msgInterop.CC = "cc@domain.com";
// Set the message subject
msgInterop.Subject = "Subject";
// Set some HTML text in the HTML body
msgInterop.HTMLBody = "<h3>HTML Heading 3</h3> <u>This is underlined text</u>";
// Save the MSG file in local disk
string strMsg = @"c:\\temp\TestInterop.msg";
msgInterop.SaveAs(strMsg, Outlook.OlSaveAsType.olMSG);
Aspose.Email for Java
नीचे के नमूने Aspose.Email का उपयोग करके Outlook MSG फ़ाइल बनाते हैं। यह शुद्ध Java में लिखा गया है और COM Interop का उपयोग नहीं करता। इस तरह MSG फ़ाइल बनाने के लिए Outlook स्थापित करना आवश्यक नहीं है।
// Create an instance of the Aspose.Email.MailMessage class
MailMessage msg = new MailMessage();
// Set recipients information
msg.setTo(MailAddressCollection.to_MailAddressCollection("to@domain.com"));
msg.setCC(MailAddressCollection.to_MailAddressCollection("cc@domain.com"));
// Set the subject
msg.setSubject("Subject");
// Set HTML body
msg.setHtmlBody("<h3>HTML Heading 3</h3> <u>This is underlined text</u>");
// Add an attachment
msg.getAttachments().addItem(new Attachment("test.txt"));
// Save it in local disk
String strMsg = "c:\\ TestAspose.msg";
msg.save(strMsg, SaveOptions.getDefaultMsgUnicode());