我已经在 C# 上使用 sourceforge 上名为“Koolwired.Imap”的开源项目进行了尝试。
下载邮件时没问题,但对于附件,它只列出附件的文件名。有没有人试过这个?
如果没有,还有其他更好的免费图书馆可以做同样的事情(我需要一个免费/开源的解决方案,因为我正在为我的校园项目做这个)
ImapConnect connection = new ImapConnect("imap.gmail.com", 993, true);
ImapCommand command = new ImapCommand(connection);
ImapAuthenticate auth = new ImapAuthenticate(connection, "<username>@gmail.com", "<password>");
connection.Open();
auth.Login();
string htmlbody = "";
ImapMailbox mailbox = command.Select("INBOX");
mailbox = command.Fetch(mailbox);
int mailCount = mailbox.Messages.Count;
for (int i = 0; i < mailCount ; i++)
{
ImapMailboxMessage msg = mailbox.Messages[mailCount - 1];
msg = command.FetchBodyStructure(msg);
msg.BodyParts[0].ContentEncoding = BodyPartEncoding.NONE;
msg = command.FetchBodyPart(msg, msg.HTML);
foreach (ImapMessageBodyPart a in msg.BodyParts)
{
if (a.Data != null)
{
string fileName = "";
if (a.Attachment) fileName = ParseFileName(a.Disposition);
string mimeType = a.ContentType.MediaType.ToLower();
a.ContentEncoding = BodyPartEncoding.UTF7;
htmlbody = a.Data;
}
}
}
auth.Logout();
connection.Close();