Click here to Skip to main content
13,044,935 members (40,602 online)
Rate this:
Please Sign up or sign in to vote.
I have created a windows appliction where we store login,logout and status(in or out) details of an employee depending on employee id.

Now my requirement is to send an email(local server) automatically for every half an hour consisting the employee details from DB where status value is "IN" .

Could any please help on how to proceed further.
Posted 13-Feb-13 0:26am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Add a Timer to your form, which fires every minute.
In the Timer Tick handler, check a counter - start with 30 and count it down. When it reaches zero, you need to send the email.
See here for a generic method to do that: Sending an Email in C# with or without attachments: generic routine.[^] then set the counter back to 30 ready for next time.
Harsha24 13-Feb-13 6:43am
thank you for the post.. Using the timer is ok. But how about fetching the records from database and send them as an attachment basing on the condition where status = "in".
OriginalGriff 13-Feb-13 6:48am
Use your prefered DB access method (DataAdapter, or Connection/Command pair with a Reader) with the following query:
You then rework them into an appropriate format - I don't know how you need the email organised so I can't suggest anything much at this stage.
CHill60 13-Feb-13 6:54am
Sorry about the cross-over comments - I really must refresh my screen more often
CHill60 13-Feb-13 6:53am
You could use StringBuilder to construct the body of the email rather than an attachment - or write the text to a temporary text file and attach that to the email e.g. filename = "\"" + Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()).ToString() + "\"";
CHill60 13-Feb-13 11:00am
Sorry - all contact is via CP
Maciej Los 13-Feb-13 7:07am
A 5!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Alternative if you want the email functionality separate from your UI ...

For sending an email you could use SMTP - System.Net.Mail This link[^] is a little old but covers various other methods too.

For the timing side of things (non-GUI) you could use System.Timers or System.Threading.Timer

or (if appropriate to your system) you could use the windows Task Scheduler[^] with your own code or a script e.g.[^]
Maciej Los 13-Feb-13 7:07am
Good idea! +5!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100