소개
이 문서에서는 Microsoft Outlook 개체 라이브러리 또는 2003 개체 Microsoft Office Outlook 라이브러리를 사용하여 MICROSOFT Visual C#.
추가 정보
Microsoft Visual Outlook 사용하여 HTML 형식 메시지를 보내기 위해 2002 개체 라이브러리 또는 Outlook 2003 개체 라이브러리를 사용하려면 다음 C# 단계를 수행합니다.
-
.NET Microsoft Visual Studio 또는 2005년 Microsoft Visual Studio 새 콘솔 애플리케이션 프로젝트를 만들 수 있습니다.
-
파일 메뉴에서 새로 고를 클릭한 다음, Project.
-
Project 형식에서 Visual C# 클릭합니다.
참고 Microsoft Visual C# 2005에서 유형 C# 아래에서 Project 클릭합니다. -
템플릿에서 콘솔 애플리케이션을 클릭합니다.
-
확인을 클릭합니다. 기본적으로 Class1.cs라는 파일이 만들어집니다.
참고 Microsoft Visual C# 2005에서는 Program.cs가 기본적으로 만들어집니다.
-
-
2002 개체 라이브러리 또는 Outlook 2003 개체 라이브러리에 Outlook 참조를 추가합니다. 이렇게 하려면 다음과 같이 하십시오.
-
Project 메뉴에서 참조 추가를 클릭합니다.
-
COM 탭을 클릭합니다.
-
COM 탭에서 Outlook 11.0 개체 라이브러리를 Outlook 2002를 사용하는 경우 Microsoft Outlook 10.0 개체 라이브러리를 Outlook 클릭합니다.
-
선택 을 클릭합니다.
참고 시각적 C# 2005에서 선택을 클릭할 수 있습니다. -
참조 추가 대화 상자에서 확인을 클릭합니다.
참고 선택한 라이브러리에 대한 래퍼를 생성하는 메시지가 표시되면 예를 클릭합니다.
-
-
Class1.cs 코드 창에서 기존 모든 코드를 다음 코드로 바 대체합니다.
using System;
using System.Reflection; // to use Missing.Value
// TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
// using Outlook = Microsoft.Office.Interop.Outlook;
namespace SendHTMLMail
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Alternate logon method that uses a specific profile.
// TODO: If you use this logon method,
// change the profile name to an appropriate value.
//oNS.Logon("YourValidProfile", Missing.Value, false, true);
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = "Send Using OOM in C#";
// Set HTMLBody.
String sHtml;
sHtml = "<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Sample GIF</TITLE>\n" +
"</HEAD>\n" +
"<BODY><P>\n" +
"<h1><Font Color=Green>Inline graphics</Font></h1></P>\n" +
"</BODY>\n" +
"</HTML>";
oMsg.HTMLBody = sHtml;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// TODO: Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email address");
oRecip.Resolve();
// Send.
oMsg.Send();
// Log off.
oNS.Logoff();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
}
// Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
// Default return value.
return 0;
}
}
} -
이 코드에서는 "TO DO" 주석이 있는 경우 필요한 변경을 실행합니다.
-
F5를 눌러 프로그램을 빌드한 다음 실행합니다.
-
전자 메일 메시지가 전송되고 수신된지 확인합니다.
참조
자세한 내용은 MSDN(Microsoft Developer Network) 웹 사이트를 방문하세요.
http://msdn2.microsoft.com/en/library/aa188489(office.10).aspx2002 전자 메일 Outlook 기능에 대한 자세한 정보 및 이러한 기능이 사용자 지정 솔루션에 영향을 줄 수 있는 방법에 대한 자세한 내용은 다음 문서 번호를 클릭하여 Microsoft 기술 자료에서 문서를 볼 수 있습니다.
290500 2002년의 개발자 관련 전자 메일 보안 기능에 Outlook 설명