gpt4 book ai didi

C# Gmail 设置启用 POP3

转载 作者:行者123 更新时间:2023-11-30 17:21:02 32 4
gpt4 key购买 nike

你好,

我正在使用此库以编程方式从 gmail 帐户检索邮件 http://mailsystem.codeplex.com/ .

当我在“转发和 POP/IMAP”中将“为所有邮件启用 POP”设置为 OK 后第一次运行我的应用程序时,一切正常(我得到消息计数和所有消息的列表)设置菜单中的选项卡。但是当我再次运行它时,没有消息被检索到。如果我再次为所有邮件设置启用 POP,应用程序将再次运行。

我认为我必须在运行检索邮件代码之前以编程方式设置“为所有邮件启用 POP”。

有谁知道如何在 C# 和 asp.net 中以编程方式执行此操作?

我使用的代码:

Pop3Client pop = new Pop3Client();
try
{
Label7.Text = string.Format("Connection to the pop 3 server : {0}", "pop.gmail.com ");
pop.ConnectSsl("pop.gmail.com", 995, TextBox4.Text, TextBox5.Text);

Label7.Text += string.Format("Message Count: {0}", pop.MessageCount.ToString());
MessageCollection mc = new MessageCollection();
for (int n = 1; n < pop.MessageCount + 1; n++)
{
Message newMessage = pop.RetrieveMessageObject(n);
mc.Add(newMessage);

Label7.Text += string.Format("Message ({0}) : {1} ", n.ToString(), newMessage.Subject);
}
}

catch (Pop3Exception pexp)
{
Label7.Text = string.Format("Pop3 Error: {0} ", pexp.Message);
}

catch (Exception ex)
{
Label7.Text = string.Format("Failed: {0} ", ex.Message);
}

finally
{
if (pop.IsConnected)
{
pop.Disconnect();
}
}

我正在使用我之前提到的来源中的 ActiveUp.Net.Mail 库。

最佳答案

您是否正在尝试获取 IMAP4 行为与 POP3 ?

使用 POP3,电子邮件通常会在检索到后从服务器中删除。然后,下次您连接时,您的应用程序中将只有新消息可用。等等。

使用 IMAP4,邮件保留在服务器上。这是一种不同的方法。您必须在本地维护一个与您的 IMAP4 服务器同步的状态。

关于C# Gmail 设置启用 POP3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3803218/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com