Outlook 메시지 (MSG) 파일 만들기
Contents
[
Hide
]
우리의 마이그레이션 팁은 Aspose 제품을 사용하여 애플리케이션을 개선하고 기존 자동화에 대한 의존성을 없앨 수 있는 방법을 보여줍니다.
이 마이그레이션 팁은 Outlook 메시지 (MSG) 파일을 만드는 방법을 보여줍니다. Microsoft Office 자동화 및 Aspose.Email. 코드 샘플은 MSG 파일의 기본 속성 - To, Cc, Subject 및 HTML 본문 - 을 설정한 후 파일을 디스크에 저장합니다.
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());