获取 email
public List<Mime> GetEmails(string pop3Server, string pop3Port, string username, string password)
{
bool pop3UseSsl = false;
List<string> gotEmailIds = new List<string>();
List<Mime> result = new List<Mime>();
using (POP3_Client pop3 = new POP3_Client())
{
try
{
pop3.Connect(pop3Server, Convert.ToInt32(pop3Port), pop3UseSsl);
pop3.Authenticate(username, password, false);
POP3_ClientMessageCollection infos = pop3.Messages;
foreach (POP3_ClientMessage info in infos)
{
if (gotEmailIds.Contains(info.UID))
continue;
byte[] bytes = info.MessageToByte();
gotEmailIds.Add(info.UID);
Mime mime = Mime.Parse(bytes);
result.Add(mime);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
return result;
}
删除 email
public void DeleteMail()
{
using (POP3_Client c = new POP3_Client())
{
c.Connect(pop3Server, Convert.ToInt32(pop3Port));
c.Authenticate(username, password, false);
if (c.Messages.Count > 0)
{
foreach (POP3_ClientMessage mail in c.Messages)
{
mail.MarkForDeletion();
}
}
}
}