任何熟悉MailSystem.NET的人?MailSystem.NET IMAP4,將郵件標記爲未讀
我有一個應用程序定期檢查一個Gmail郵件帳戶的新郵件。如果主題標題包含特定短語,則採取行動。不過,我需要稍微修改該應用,以將某些郵件標記爲未讀。
這裏是現有的代碼。點擊按鈕調用logInLogOut()子並啓動一個定時器,該定時器負責通過調用另一個線程中的checkNewMail()子來定期檢查新郵件。該應用程序按預期工作,但以下可能不是最好的方式。
private void logInLogOut()
{
try
{
Client.ConnectSsl(txtIMAPServer.Text, int.Parse(txtIMAPPort.Text));
Client.Login(@txtUserName.Text, txtPassword.Text);
globalClientConnected = true;
}
catch (Exception ex)
{
globalClientConnected = false;
}
}
private void checkNewMail()
{
if (globalClientConnected)
{
foreach (ActiveUp.Net.Mail.Message email in GetUnreadMails("Inbox"))
{
string from = parseEmailAddress(email.From.ToString());
string subject = email.Subject;
string receivedDateTime = email.ReceivedDate.Date.ToString()
string updateString = receivedDateTime + ", " + from + ", " + subject + "\r\n";
if (subject.Contains("ABC"))
{
string to = from;
try
{
//do something
}
catch (Exception ex)
{
//bla bla
}
}
else
{
//If mail subject not like "ABC"
//Do something else
//Mark the mail as unread
}
}
}
}
那麼謝謝你的!當你第二次看時,你會發現很驚人的東西:) – user1776480