Outlook'ta öğeleri program aracılığıyla taşıma
Bu örnek, okunmamış e-posta iletilerini Gelen Kutusu'ndanTest adlı bir klasöre taşır. Örnek yalnızca alanda TestSubject
sözcüğü bulunan iletileri taşır.
Şunlar için geçerlidir: Bu konudaki bilgiler Outlook için VSTO Eklenti projeleri için geçerlidir. Daha fazla bilgi için bkz. Office uygulaması ve proje türüne göre kullanılabilen özellikler.
Örnek
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += new Microsoft.Office.Interop.Outlook.
ApplicationEvents_11_NewMailEventHandler
(ThisAddIn_NewMail);
}
private void ThisAddIn_NewMail()
{
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application.
ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = (Outlook.Items)inBox.Items;
Outlook.MailItem moveMail = null;
items.Restrict("[UnRead] = true");
Outlook.MAPIFolder destFolder = inBox.Folders["Test"];
foreach (object eMail in items)
{
try
{
moveMail = eMail as Outlook.MailItem;
if (moveMail != null)
{
string titleSubject = (string)moveMail.Subject;
if (titleSubject.IndexOf("Test") > 0)
{
moveMail.Move(destFolder);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Kodu derleme
Bu örnek şunları gerektirir:
Test adlı bir Outlook posta klasörü.
Alanda Test
Subject
sözcüğünü içeren bir e-posta iletisi.