c# - OpenPop - 获取电子邮件详细信息 c#

标签 c# email openpop

我正在尝试制作一种电子邮件接收器,到目前为止我有一个按钮,按下该按钮会显示最新电子邮件的正文,这正是我想要的,除了我还想要主题、发件人和最重要的时间。代码如下

public static List<OpenPop.Mime.Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
    using (Pop3Client client = new Pop3Client())
    {
        client.Connect(hostname, port, useSsl);
        client.Authenticate(username, password);
        int messageCount = client.GetMessageCount();
        List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);

        for (int i = messageCount; i > 0; i--)
        {
            allMessages.Add(client.GetMessage(i));
        }
        return allMessages;
    }
}

private void button1_Click(object sender, EventArgs e)
{
    List<OpenPop.Mime.Message> allaEmail = FetchAllMessages("pop.gmail.com", 995, true, "xx", "xx");

    StringBuilder builder = new StringBuilder();
    OpenPop.Mime.Message message = allaEmail[0];
    OpenPop.Mime.MessagePart plainText = message.FindFirstPlainTextVersion();
    if (plainText != null)
    {
        builder.Append(plainText.GetBodyAsText());
        MessageBox.Show(builder.ToString());
    }

    OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion();
    if (html != null)
    {
        builder.Append(html.GetBodyAsText());
    }
}

最佳答案

您可以使用 message.Headers.Subjectmessage.Headers.Date 属性来获取您想要的内容。

关于c# - OpenPop - 获取电子邮件详细信息 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015802/

相关文章:

html - 编码要通过电子邮件发送的HTML,Outlook中的Google字体默认为Times New Roman,该如何解决?

c# - 如何使用 pop3 c# 从 Yahoo mail 中读取最新的电子邮件

c# - ServerTags 在 OnClientClick 中不起作用

c# - 安全地验证客户端到服务器

c# - Int64(长整型)和线程安全

c# - OpenPop : how can I turn off DEBUG printing?

c# - 找不到 openpop.NET 文件、MessageHeader、RfcMailAddress、消息

c# - 响应重定向不起作用

java - 是否可以将输出缓冲到 Log4j Mail Appender?

python - 如何在 poplib 中仅搜索包含附件的电子邮件