Vytvoření souboru Outlook Message (MSG) v Aspose.Email
Contents
[
Hide
]
Chcete‑li použít Automatizaci Office, musí být na počítači, kde kód běží, nainstalován Microsoft Outlook. Je také nutná reference na Outlook.interop.dll.
VSTO
// 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 = "TestInterop.msg";
msgInterop.SaveAs(strMsg, Outlook.OlSaveAsType.olMSG);
Aspose.Email
Níže uvedené ukázky používají Aspose.Email k vytvoření souboru Outlook MSG. Je psán v čistém .NET a nepoužívá COM Interop. Instalace Outlook není potřebná pro vytváření souboru msg tímto způsobem.
// Create an instance of the Aspose.Email.MailMessage class
MailMessage msg = new MailMessage();
// Set recipients information
msg.To = "to@domain.com";
msg.CC = "cc@domain.com";
// Set the subject
msg.Subject = "Subject";
// Set HTML body
msg.HtmlBody = "<h3>HTML Heading 3</h3> <u>This is underlined text</u>";
// Add an attachment
msg.Attachments.Add(new Attachment("image.bmp"));
// Save it in local disk
string strMsg = "TestAspose.msg";
msg.Save(strMsg, MessageFormat.Msg);