[C#/OUTLOOK] ApplicationEvents_11_Event 인터페이스 : NewMailEx 이벤트를 사용해 신규 메일 수신시 처리하기
C#/Outlook 2021. 6. 19. 00:35728x90
반응형
728x170
▶ CustomAddIn.cs
using Microsoft.Office.Interop.Outlook;
using System;
namespace TestProject
{
/// <summary>
/// 커스텀 애드인
/// </summary>
public partial class CustomAddIn
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 애플리케이션
/// </summary>
private Application application = null;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 커스텀 애드인 시작시 처리하기 - CustomAddIn_Startup(sender, e)
/// <summary>
/// 커스텀 애드인 시작시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void CustomAddIn_Startup(object sender, EventArgs e)
{
this.application = Application;
this.application.NewMailEx += application_NewMailEx;
}
#endregion
#region 커스텀 애드인 셧다운시 처리하기 - CustomAddIn_Shutdown(sender, e)
/// <summary>
/// 커스텀 애드인 셧다운시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void CustomAddIn_Shutdown(object sender, EventArgs e)
{
}
#endregion
#region 애플리케이션 신규 메일 수신시 처리하기 - application_NewMailEx(entryIDCollection)
/// <summary>
/// 애플리케이션 신규 메일 수신시 처리하기
/// </summary>
/// <param name="entryIDCollection">엔트리 ID 컬렉션</param>
private void application_NewMailEx(string entryIDCollection)
{
string[] entryIDArray = entryIDCollection.Split(',');
foreach(string entryID in entryIDArray)
{
MailItem mailItem = this.application.ActiveExplorer().Session.GetItemFromID(entryID);
if(mailItem != null)
{
System.Windows.Forms.MessageBox.Show(mailItem.Subject);
}
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region VSTO에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(CustomAddIn_Startup );
this.Shutdown += new System.EventHandler(CustomAddIn_Shutdown);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요