다음을 통해 공유


방법: 프로그래밍 방식으로 전자 메일 보내기

이 예제에서는 전자 메일 주소에 example.com이라는 도메인 이름이 있는 연락처로 전자 메일 메시지를 보냅니다.

적용 대상: 이 항목의 정보는 Outlook 2007 및 Outlook 2010의 응용 프로그램 수준 프로젝트에 적용됩니다. 자세한 내용은 Office 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

예제

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    SendEmailtoContacts()
End Sub

Private Sub SendEmailtoContacts()
    Dim subjectEmail As String = "Meeting has been rescheduled."
    Dim bodyEmail As String = "Meeting is one hour later."
    Dim sentContacts As Outlook.MAPIFolder = Me.Application.ActiveExplorer() _
        .Session.GetDefaultFolder(Outlook _
        .OlDefaultFolders.olFolderContacts)
    For Each contact As Outlook.ContactItem In sentContacts.Items()
        If contact.Email1Address.Contains("example.com") Then
            CreateEmailItem(subjectEmail, contact _
            .Email1Address, bodyEmail)
        End If
    Next
End Sub

Private Sub CreateEmailItem(ByVal subjectEmail As String, _
    ByVal toEmail As String, ByVal bodyEmail As String)
    Dim eMail As Outlook.MailItem = Me.Application.CreateItem _
        (Outlook.OlItemType.olMailItem)
    With eMail
        .Subject = subjectEmail
        .To = toEmail
        .Body = bodyEmail
        .Importance = Outlook.OlImportance.olImportanceLow
        .Send()
    End With
End Sub
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    SendEmailtoContacts();
}

private void SendEmailtoContacts()
{
    string subjectEmail = "Meeting has been rescheduled.";
    string bodyEmail = "Meeting is one hour later.";
    Outlook.MAPIFolder sentContacts = (Outlook.MAPIFolder)
        this.Application.ActiveExplorer().Session.GetDefaultFolder
        (Outlook.OlDefaultFolders.olFolderContacts);
    foreach (Outlook.ContactItem contact in sentContacts.Items)
    {
        if (contact.Email1Address.Contains("example.com"))
        {
            this.CreateEmailItem(subjectEmail, contact
                .Email1Address, bodyEmail);
        }
    }
}

private void CreateEmailItem(string subjectEmail,
       string toEmail, string bodyEmail)
{
    Outlook.MailItem eMail = (Outlook.MailItem)
        this.Application.CreateItem(Outlook.OlItemType.olMailItem);
    eMail.Subject = subjectEmail;
    eMail.To = toEmail;
    eMail.Body = bodyEmail;
    eMail.Importance = Outlook.OlImportance.olImportanceLow;
    ((Outlook._MailItem)eMail).Send();
}

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

  • 전자 메일 주소에 도메인 이름 example.com이 있는 연락처

강력한 프로그래밍

도메인 이름 example.com을 검색하는 필터 코드를 제거하지 마십시오. 필터를 제거하면 솔루션에서 모든 연락처로 전자 메일 메시지를 보냅니다.

참고 항목

작업

방법: 전자 메일 항목 만들기

방법: Outlook 연락처 액세스

방법: 전자 메일 메시지를 받은 경우 작업 수행

개념

메일 항목 작업