using DSWeb.Common.DB; using log4net; using MailKit.Net.Smtp; using MimeKit; using Quartz; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; namespace DSWeb.Job.Common { /// /// 清理过期邮件 /// public class ClearMailJob : IJob { private CommonDataContext commonDataContext = new CommonDataContext(); private ILog logger = LogManager.GetLogger("ClearMailJob"); public void Execute(IJobExecutionContext context) { DateTime dtClear = DateTime.Today.AddDays(-7); var clearMailList = commonDataContext.MailSend.Where(sm => sm.CreateTime < dtClear).ToList(); if (clearMailList.Count > 0) { logger.Debug($"准备清理过期邮件{clearMailList.Count}封"); clearMailList.ForEach(m => commonDataContext.MailSend.Remove(m)); commonDataContext.SaveChanges(); logger.Debug($"准备清理过期邮件完成"); } } } }