728x90
반응형
728x170
▶ CustomAddIn.cs
using Microsoft.Office.Interop.Outlook;
using System;
using System.IO;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 커스텀 애드인
/// </summary>
public partial class CustomAddIn
{
//////////////////////////////////////////////////////////////////////////////////////////////////// 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)
{
Application.NewMail += Application_NewMail;
}
#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_NewMail()
/// <summary>
/// 애플리케이션 신규 메일 수신시 처리하기
/// </summary>
private void Application_NewMail()
{
MAPIFolder inboxFolder = Application.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Items inboxFolderItems = inboxFolder.Items;
inboxFolderItems = inboxFolderItems.Restrict("[Unread] = true");
string saveDirectoryPath = @"C:\TestFileSave";
try
{
foreach(object item in inboxFolderItems)
{
MailItem mailItem = item as MailItem;
if(mailItem != null)
{
if(mailItem.Attachments.Count > 0)
{
if(!Directory.Exists(saveDirectoryPath))
{
Directory.CreateDirectory(saveDirectoryPath);
}
for(int i = 1; i <= mailItem.Attachments.Count; i++)
{
string saveFilePath = Path.Combine(saveDirectoryPath, mailItem.Attachments[i].FileName);
mailItem.Attachments[i].SaveAsFile(saveFilePath);
}
}
}
}
}
catch(System.Exception exception)
{
MessageBox.Show(exception.ToString());
}
}
#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
반응형
그리드형(광고전용)
'C# > Outlook' 카테고리의 다른 글
[C#/OUTLOOK] _Items 인터페이스 : Find/FindNext 메소드를 사용해 특정 폴더 검색하기 (0) | 2021.06.17 |
---|---|
[C#/OUTLOOK] Folder 인터페이스 : 루트 폴더 구하기 (0) | 2021.06.17 |
[C#/OUTLOOK] _MailItem 인터페이스 : UserProperties 속성을 사용해 사용자 속성 추가하기 (0) | 2021.06.16 |
[C#/OUTLOOK] _Items 인터페이스 : Restrict 메소드를 사용해 받은 편지함에서 읽지 않은 메일 검색하기 (0) | 2021.06.16 |
[C#/OUTLOOK] _MailItem 인터페이스 : Attachments 속성을 사용해 메일 송신시 파일 첨부하기 (0) | 2021.06.16 |
[C#/OUTLOOK] ApplicationEvents_11_Event 인터페이스 : NewMail 이벤트를 사용해 신규 메일 수신시 처리하기 (0) | 2021.06.16 |
[C#/OUTLOOK] ItemsEvents_Event 인터페이스 : ItemAdd 이벤트를 사용해 메일 수신시 처리하기 (0) | 2021.06.16 |
[C#/OUTLOOK] _MailItem 인터페이스 : Send 메소드를 사용해 메일 보내기 (0) | 2021.06.16 |
[C#/OUTLOOK] 연락처 삭제하기 (0) | 2021.06.16 |
[C#/OUTLOOK] 연락처에서 메일 주소 검색하기 (0) | 2021.06.16 |
댓글을 달아 주세요