You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB
C#

11 months ago
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
{
/// <summary>
/// 清理过期邮件
/// </summary>
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($"准备清理过期邮件完成");
}
}
}
}