Outlook 메시지 (MSG) 파일 만들기

Office 자동화

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());