如何在截止日期前7天向会员发送自动邮件? [英] How to send automatic mail to members before 7 days from due date?
本文介绍了如何在截止日期前7天向会员发送自动邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个申请,所有会员都应该在截止日期前一周收到电子邮件。
例如。如果截止日期是6月30日,那么会员应该在6月23日收到电子邮件以支付会费。
对于发送邮件,我使用了以下代码:
Hello,
I have an application where all the members should receive an email 1 week before the due date.
for eg. If the due date is 30th June then the members should receive email on 23rd June for paying their dues.
For sending mail I have used following code:
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("from@abc.com");
Msg.To.Add("to@abc.com");
Msg.Subject = "Message from Website";
string body = "Your maintenance for month June is INR 500 and should be paid by 30th June. If paid after this date your amount will be 600. Please ignore if already paid. ";
Msg.Body = body;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "localhost";
smtp.Port = 25;
smtp.Send(Msg);
Msg = null;
请帮我解决这个。
提前致谢。
Please help me to solve this.
Thanks in advance.
推荐答案
public void SendMail()
{
DateTime dueDate = Convert.ToDateTime("06/30/2014");
DateTime currentDate = DateTime.Now;
System.TimeSpan diffDays = dueDate.Subtract(currentDate);
if (diffDays.Days == 7)
{
//Write the logic to send mail;
}
}
如上所述构建一个Windows服务并安排它每天运行一次。
Build a windows service as above and schedule it run once a day.
这篇关于如何在截止日期前7天向会员发送自动邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文