Click here to Skip to main content
15,886,105 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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.
Posted
Updated 22-Jun-14 21:07pm
v2
Comments
Bh@gyesh 23-Jun-14 2:09am    
Make window service for sending mail and write your logic for date compare and send email within it. It will solve your problem.
Dhanashri_G 23-Jun-14 2:20am    
Thanks for your reply. Is there any other way rather than using windows service?
Bh@gyesh 23-Jun-14 2:27am    
You can use window scheduler also for this task. the main thing is sending mail before one week so, there should be some application running on your system that will check for date validation without it this thing u need to do manually.. :)
Dhanashri_G 23-Jun-14 2:32am    
Sorry I forgot to mention that this is a web application and i have hosted this on server.
Bh@gyesh 23-Jun-14 2:37am    
no issue. you can use window service..

1 solution

C#
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;
           }

       }


Build a windows service as above and schedule it run once a day.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900