本文轉自:https://blog.csdn.net/yanlovehan/article/details/8500449spa
//引用Microsoft.Office.Interop.Outlook.dll
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Interop.Outlook;.net
//建立Application
Outlook.Application myOutlookApp = new Outlook.Application();
Outlook.NameSpace myNameSpace = myOutlookApp.GetNamespace("MAPI");對象
//本地郵箱
Outlook.MAPIFolder myFolderInbox = myNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);//獲取收件箱對象,如獲取其餘箱可在參數中控制
Outlook.MAPIFolder myFolder = myFolderInbox.Folders["xx"];//「xx」爲收件箱下的一個文件夾
Outlook.MAPIFolder MyParentFolder = myFolderInbox.Parent as Outlook.MAPIFolder;//獲取收件箱上一級的文件夾對象,以次來獲取與收件箱同級的文件夾
Outlook.MAPIFolder MyNewFolder = MyParentFolder.Folders["yy"];//「yy」爲與收件箱同級的文件夾blog
//公共郵箱
string publicMailBoxName="jpn_eco_ci04@hp.com";
Outlook.Recipient objRecipient = myNameSpace.CreateRecipient(publicMailBoxName);//jpn_eco_ci04@hp.com爲公共郵箱地址的全名稱
Outlook.MAPIFolder myFolderInbox = myNameSpace.GetSharedDefaultFolder(objRecipient, OlDefaultFolders.olFolderInbox);
Outlook.MAPIFolder myFolder = myFolderInbox.Parent as Outlook.MAPIFolder;
Outlook.MAPIFolder myNewFolder = myFolder.Folders["(Z) 処理済"];排序
//指定發送的郵箱爲公共郵箱
string publicMailBoxName = "vpchi.dlbc@hp.com";
mail.SentOnBehalfOfName = publicMailBoxName;ip
//***篩選***
//根據Subject屬性對郵件進行篩選
const string subject = "BIS B2B Document Delivery";
string sFilter = "@SQL=" + "\"" + "urn:schemas:httpmail:subject" + "\"" + " like '%" + subject + "%'";
//根據郵件的收取時間進行篩選
Outlook.Items myMails = myFolderInbox.Items.Restrict(sFilter) as Outlook.Items;
//通配符
通配符
%
包含零個或多個字符的任意字符串。
WHERE title LIKE '%computer%' 將查找在書名中任意位置包含單詞 "computer" 的全部書名。
_(下劃線)
任何單個字符。
WHERE au_fname LIKE '_ean' 將查找以 ean 結尾的全部 4 個字母的名字(Dean、Sean 等)。
[ ]
指定範圍 ([a-f]) 或集合 ([abcdef]) 中的任何單個字符。
WHERE au_lname LIKE '[C-P]arsen' 將查找以 arsen 結尾而且以介於 C 與 P 之間的任何單個字符開始的做者姓氏,例如 Carsen、Larsen、Karsen 等。在範圍搜索中,範圍包含的字符可能因排序規則的排序規則而異。
[^]
不屬於指定範圍 ([a-f]) 或集合 ([abcdef]) 的任何單個字符。
WHERE au_lname LIKE 'de[^l]%' 將查找以 de 開始而且其後的字母不爲 l 的全部做者的姓氏。ci
//1.獲取郵件對象
//2.根據篩選條件移動郵件
//3.獲取附件並將其存到本地磁盤
const string filePath = @"C:\Print Attachment Folder\";
if (MyMails.Count != 0)
{
do
{
Outlook.MailItem myMail = myMails[1] as Outlook.MailItem;
Outlook.Attachments myAttachments = myMail.Attachments as Outlook.Attachments;
foreach (Outlook.Attachment myAttachment in myAttachments)
{
myAttachment.SaveAsFile(filePath + myAttachment.FileName);
}
myMail.Move(MyMoveFolder);
myMails = MyFolderInbox.Items.Restrict(sfilter) as Outlook.Items;
}
while (myMails.Count != 0);
}字符串
//建立新郵件並添加附件發送
Outlook.Application myOutlookApp = new Outlook.Application();
Outlook.MailItem mail = myOutlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Attachments.Add(TemplateExcel, Outlook.OlAttachmentType.olEmbeddeditem, 1, System.Type.Missing);
mail.Subject = "QC Check File";
string to = string.Empty; ;
for (int i = 0; i < mails.Count; i++)
{
to = to + mails[i] + ";";
}
mail.To = to;
mail.Send();
---------------------
做者:劉巖Tony
來源:CSDN
原文:https://blog.csdn.net/yanlovehan/article/details/8500449
版權聲明:本文爲博主原創文章,轉載請附上博文連接!get