Created
October 29, 2017 08:01
-
-
Save Lycheejam/0d421b5fcf219dab5ea61b7951ba4006 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Outlook = Microsoft.Office.Interop.Outlook; | |
using System.Windows.Forms; | |
using System.IO; | |
namespace fileChk | |
{ | |
public partial class ThisAddIn | |
{ | |
private void ThisAddIn_Startup(object sender, System.EventArgs e) | |
{ | |
Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend); | |
} | |
private void Application_ItemSend(object Item, ref bool Cancel) | |
{ | |
Outlook.MailItem mail = new Outlook.MailItem(); | |
//添付ファイルがあるならば | |
if(mail.Attachments.Count > 1) | |
{ | |
//とりあえず添付ファイル全部見てみる | |
for (int i = 0; i < mail.Attachments.Count; i++) | |
{ | |
//サンプルなんでエクセルファイルのみ判定してるけど | |
//ここですべてのword,excelファイルを判定する。 | |
if ("xlsx" == Path.GetExtension(mail.Attachments[i].FileName)) | |
{ | |
DialogResult result = MessageBox.Show | |
("Officeファイルがあります。変更履歴を確認しましたか?", | |
"メールを送信しますか?", | |
MessageBoxButtons.YesNoCancel, | |
MessageBoxIcon.Exclamation, | |
MessageBoxDefaultButton.Button2); | |
if (result == DialogResult.Yes) | |
{ | |
//送信 | |
} | |
else if ((result == DialogResult.No) || (result == DialogResult.Cancel)) | |
{ | |
//送信しない | |
Cancel = true; | |
} | |
//ループ脱出 | |
break; | |
} | |
} | |
} | |
} | |
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) | |
{ | |
//注: Outlook はこのイベントを発行しなくなりました。Outlook が | |
// シャットダウンする際に実行が必要なコードがある場合は、http://go.microsoft.com/fwlink/?LinkId=506785 を参照してください。 | |
} | |
#region VSTO で生成されたコード | |
/// <summary> | |
/// デザイナーのサポートに必要なメソッドです。 | |
/// このメソッドの内容をコード エディターで変更しないでください。 | |
/// </summary> | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(ThisAddIn_Startup); | |
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment