我希望实现与此类似的功能:
Notify C# Client, when SMTP Server receive a new Email
这很好用。那种方法" NewMessageReceived"每次收到新邮件都会成功通话。
但问题是我无法取邮件。我只用这种方法得到了INBOX的总数。
此代码使用库:MailSystem.net
我的代码如下:
Imap4Client _imap;
public static int cnt = 0;
protected void Application_Start(object sender, EventArgs e)
{
var worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(StartIdleProcess);
if (worker.IsBusy)
worker.CancelAsync();
worker.RunWorkerAsync();
}
private void StartIdleProcess(object sender, DoWorkEventArgs e)
{
if (_imap != null && _imap.IsConnected)
{
_imap.StopIdle();
_imap.Disconnect();
}
_imap = new Imap4Client();
_imap.ConnectSsl(ConfigurationManager.AppSettings["IncomingServerName"], Convert.ToInt32(ConfigurationManager.AppSettings["InPort"]));
_imap.Login(ConfigurationManager.AppSettings["EmailAddress"], ConfigurationManager.AppSettings["Password"]);
var inbox = _imap.SelectMailbox("INBOX");
_imap.NewMessageReceived += new NewMessageReceivedEventHandler(NewMessageReceived);
inbox.Subscribe();
_imap.StartIdle();
}
public static void NewMessageReceived(object source, NewMessageReceivedEventArgs e)
{
cnt = e.MessageCount; //Inbox Count
//here i want to fetch all unread mail from inbox
}
我找到了以下解决方案来获取未读邮件:
http://mailsystem.codeplex.com/discussions/651129
我说要使用MailKit库。由于我已经在使用MailSystem.net库,有没有办法通过只使用一个库来实现我的要求?
我也准备好使用任何其他库。
请给我一些建议。感谢
答案 0 :(得分:2)