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

Spire.Email允许开发人员搜索符合给定搜索条件的电子邮件的邮箱,本文介绍了如何使用Spire.Email组件搜索电子邮件。

详细步骤:

Step 1:创建一个ImapClient实例。

ImapClient imap = new ImapClient();

Step 2:设置主机,端口,认证和连接协议。

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

Step 3:连接imap服务器。

imap.Connect();

Step 4:选择收件箱文件夹。

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

完整代码:

[C#]

//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)

慧都控件网

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值