我正在使用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呢?
发布于 2018-08-22 17:23:08
您可以使用Encoding从字节流中获取字符串:
string result = Encoding.UTF8.GetString(bytes);检查您的字符串是否为utf8、ascii或其他类型。您可能需要对此进行一些更改。
发布于 2019-12-09 23:19:20
您可以通过以下方式使用Encoding:
string result = Encoding.UTF8.GetString(bytes, 0, bytes.length);https://stackoverflow.com/questions/51963552
复制相似问题