Spire.Email 教程:在C#,VB.NET中搜索電子郵件

Spire.Email容許開發人員搜索符合給定搜索條件的電子郵件的郵箱,本文介紹瞭如何使用Spire.Email組件搜索電子郵件。html

詳細步驟:服務器

Step 1:建立一個ImapClient實例。3d

ImapClient imap = new ImapClient();

Step 2:設置主機,端口,認證和鏈接協議。server

imap.Host = "outlook.office365.com";
imap.Port = 143;
imap.Username = "LeonDavisLD@outlook.com";
imap.Password = "password";
imap.ConnectionProtocols = ConnectionProtocols.Ssl;

Step 3:鏈接imap服務器。htm

imap.Connect();

Step 4:選擇收件箱文件夾。blog

imap.Select("Inbox");

Step 5:搜索符合搜索條件的文件夾中的電子郵件。圖片

//Search email messages sent from 「Alice」
ImapMessageCollection messages = imap.Search("'From' Contains 'Alice'");
Console.WriteLine("Number of messages sent from Alice: " + messages.Count);
//Search email messages with 「Spire」 string in subject
messages = imap.Search("'Subject' Contains 'Spire'");
Console.WriteLine("Number of messages with 'Spire' in subject: " + messages.Count);

截圖:開發

圖片1

完整代碼:get

[C#]string

//Create an ImapClient instance
ImapClient imap = new ImapClient();
//Set host, port, authentication and connection protocol
imap.Host = "outlook.office365.com";
imap.Port = 143;
imap.Username = "LeonDavisLD@outlook.com";
imap.Password = "password";
imap.ConnectionProtocols = ConnectionProtocols.Ssl;
//Connect the imap server
imap.Connect();
//Select Inbox folder
imap.Select("Inbox");
//Search email messages sent from "Alice"
ImapMessageCollection messages = imap.Search("'From' Contains 'Alice'");
Console.WriteLine("Number of messages sent from Alice: " + messages.Count);
//Search email messages with 「Spire」 string in subject
messages = imap.Search("'Subject' Contains 'Spire'");
Console.WriteLine("Number of messages with 'Spire' in subject: " + messages.Count);

[VB.NET]

'Create an ImapClient instance
Dim imap As New ImapClient()
'Set host, port, authentication and connection protocol
imap.Host = "outlook.office365.com"
imap.Port = 143
imap.Username = "LeonDavisLD@outlook.com"
imap.Password = "password"
imap.ConnectionProtocols = ConnectionProtocols.Ssl
'Connect the imap server
imap.Connect()
'Select Inbox folder
imap.[Select]("Inbox")
'Search email messages sent from "Alice"
Dim messages As ImapMessageCollection = imap.Search("'From' Contains 'Alice'")
Console.WriteLine("Number of messages sent from Alice: " + messages.Count)
'Search email messages with 「Spire」 string in subject
messages = imap.Search("'Subject' Contains 'Spire'")
Console.WriteLine("Number of messages with 'Spire' in subject: " + messages.Count)

慧都控件網

相關文章
相關標籤/搜索