任何熟悉 MailSystem.NET 的人?
我有一个应用程序,它会定期检查 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
}
}
}
}