【问题标题】:OpenPop.net get actual message text from attachmentOpenPop.net 从附件中获取实际的消息文本
【发布时间】:2019-01-28 12:28:43
【问题描述】:

我正在使用 OpenPop.net 尝试从给定收件箱中的所有电子邮件中解析我们的链接。我发现这种方法可以获取所有消息:
`

  public static List<OpenPop.Mime.Message> FetchAllMessages(stringhostname,  
int port, bool useSsl, string username, string password)    
 {

 // The client disconnects from the server when being disposed


    using (Pop3Client client = new Pop3Client())
    {

        // Connect to the server
        client.Connect(hostname, port, useSsl);

        // Authenticate ourselves towards the server
        client.Authenticate(username, password);

        // Get the number of messages in the inbox
        int messageCount = client.GetMessageCount();

        // We want to download all messages
        List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);

        // Messages are numbered in the interval: [1, messageCount]
        // Ergo: message numbers are 1-based.
        // Most servers give the latest message the highest number
        for (int i = messageCount; i > 0; i--)
        {
            allMessages.Add(client.GetMessage(i)); 
             foreach (var attachment in msg.FindAllAttachments())
             {
                string str = enc.GetString(attachment.Body);
             }                   
        }

        client.Disconnect();

        // Now return the fetched messages
        return allMessages;
    }
}`

还尝试使用这种方式通过 Ascii 字符进行编码:

但是,不能成功.. 我想需要附件文件中的 html。但在 attachment.Body 中给出字节数组。那么,字节数组如何转 HTML 呢?

【问题讨论】:

    标签: c# asp.net openpop


    【解决方案1】:

    您可以使用 Encoding 从字节流中获取字符串:

    string result = Encoding.UTF8.GetString(bytes);
    

    检查您的字符串是 utf8、ascii 还是其他。你可能需要稍微改变一下。

    【讨论】:

    • 尝试了这种方式但无法成功。
    【解决方案2】:

    您可以通过以下方式使用编码:

    string result = Encoding.UTF8.GetString(bytes, 0, bytes.length);
    

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多