Solved

Send Email before certain days from today's date

Posted on 2010-11-11
6
868 Views
Last Modified: 2013-04-16
hi,

How can i send an email certain days from now in C# (Win Forms). Say today is January 1 2010. Now i fix an appointment with doctor on January 10 2010. But i wish that a reminder email (regarding appointment) needs to be sent 3 days before (i.e. January 7 2010). I am having an email code with me.

My requirements: Visual Studio 2005, C# (vb would also do), WinForms (Windows based applications)

Please help me how to achieve this?

Let me know if anything from me is needed.
0
Comment
Question by:meispisces
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Assisted Solution

by:AliSyed
AliSyed earned 166 total points
ID: 34115181
DateTime EmailDate = DateTime.Appointmentdate.AddDays(-3);
You can put this emaildate in your db and send a reminder on that date

Ali Syed
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 166 total points
ID: 34117804

You need  a database to store the appointments and reminder days and status of the reminder.

ReminderDate,  Status, AppointmentDate

Calculate the the date for the reminder from the AppointmentDate as described by AliSyed

Your application should run a aquery to once or twice a day fetch all records that have the ReminderDate equal to current date and status of not sent. Iterate through this records sending the emails one at a time and set the status to sent if successful.
If using SQL Server, you can set up sql server to do this for you.

you can use a function in c# such as
public bool SendEmail(string EmailFrom, string EmailTo, string EmailSubject, string EmailMessage, string EmailHost)
{
  try
  {
    MailMessage Msg = new MailMessageEmailFrom, EmailTo, EmailSubject, EmailMessage);
    SmtpClient Client = new SmtpClientEmailHost);
    Client.UseDefaultCredentials = true;
    Client.Send(msg);

    return true;
  }
  catch (Exception ex)
  {
     return false
  }
}
0
 
LVL 13

Accepted Solution

by:
devlab2012 earned 168 total points
ID: 34133781
create a table with following structure:

---tblEVENTS
EventID
EventDesc
EventDate
AlertBeforeDays
IsEmailed

Now, get the data from this table using a query like:

SELECT * FROM tblEvents WHERE dateAdd(d, AlertBeforeDays, getDate()) >= EventDate AND IsEmailed = 0
This query will give you information of events for which you have to send an email.

Now send an email (you mentioned that you already have code to send email) and when the email is sent successfully, set the value of IsEmailed to 1.

Okay, now the problem is how this application will automatically send the alerts? You can simplay depend upon "Task Scheduler" in Windows. Create a task to execute every day or after every few hours. For XP, click Start -> Control Panel -> Scheduled Task.

If you want to write your own code, you can use System.Threading.Timer class or Timer control.
0
 
LVL 7

Author Comment

by:meispisces
ID: 34298738
Yes please close it..
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34324605
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email attacks are the most efficient and effective way for cyber criminals and hackers to compromise a computer or network. We often find our-self second guessing the authenticity of an email message, for such instances we can follow practical princ…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question