Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 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

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.
 
Share this answer
 
Comments
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:
SELECT * FROM MyTable WHERE Status='IN'
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
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 http://msdn.microsoft.com/en-gb/library/windows/desktop/aa383614(v=vs.85).aspx[^] with your own code or a script e.g. http://www.petri.co.il/how-to-use-eventtriggersexe-to-send-e-mail-based-on-event-ids.htm[^]
 
Share this answer
 
Comments
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)



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