Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server-2008
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 1:26am
Rate this: bad
good
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.
  Permalink  
Comments
Harsha24 at 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 at 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 at 13-Feb-13 6:54am
   
Sorry about the cross-over comments - I really must refresh my screen more often
CHill60 at 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 at 13-Feb-13 11:00am
   
Sorry - all contact is via CP
Maciej Los at 13-Feb-13 7:07am
   
A 5!
Rate this: bad
good
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 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[^]
  Permalink  
Comments
Maciej Los at 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
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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