Click here to Skip to main content
12,997,914 members (58,622 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 7 Feb 2013

Automated Email System for Employee Entry Time Management

, 10 Feb 2013
Rate this:
Please Sign up or sign in to vote.
Automated Mailing System for Employee Entry time management with database backup


Every office maintains their own system to maintain the entry time of their employees inorder to make sure they are maintaining office hour properly. For my case i need to send an entry mail composed with my formal signature and the time. At my work, i usually forget to send the entry mail to the boss. So there may be some confusion whether i have attended office today in time or not. So i have decided to create an application that will help me to solve my daily problem. Today i am going to describe my way to do this.


I usually forget to send my entry mail in due time. For this reason i have decided to develop an application to do this task for me. It is actually more easier for programmers to develop an app other than to memorize to do a task. That's why the task scheduler idea came. I have also made an installer for programmers easy use, if any one wants to use it without having programming knowledge. So let's start.

Using the code 

Eventually i have deployed all possible ways to make it user friendly. I have kept in mind that non-programmers may use this application. So i developed it like that way. In my first section i will describe the programming methodology that i have used in my application and in the second section i will describe how to use my application.   

First Section:   

First of all we need to understand the scenario of the application we are developing.

Here it is : 

  1. We need to develop an application that will send mail automatically when the computer starts.
  2. We need to take input from user the mailing address (To) , network credentials and of course the user's mail address.
  3. Then we can add some signature or other necessary information that we want to send with the mail.
  4. Then we will shoot the mail.

Now the scenario is clear that what we are going to do and i am now describing how and why we are going to do this with detail elaboration with code segment. 

We will start from the second point that is "We need to take input from user the mailing address (To) , network credentials and of course the user's mail address.  "

So here are the situations that may arise. 

  • User can put wrong mail address, So we need to verify that the email address maintains the standard format.
  • Here in my case i am taking name,email,phone and designation as inputs from user. So i need to validate the phone number too. At this moment i have only allowed the phone number of U.S. as valid. So if you are from another country please kindly change the code to validate the phone number of yours.

Here is the code segment for Email validation.

if (!tbxEmail.Text.Equals(string.Empty))
       new System.Net.Mail.MailAddress(tbxEmail.Text);
   catch (Exception ex)
       MessageBox.Show("Email Not Valid" + ex);

Here is the code for Phone Number validation.

if (!tbxPhone.Text.Equals(string.Empty))
  string[] numbers = { tbxPhone.Text };
  //string sPattern = @"01[5-9][0-9]{8}$";
  const string sPattern = @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}";
  foreach (string s in numbers)
     if (!System.Text.RegularExpressions.Regex.IsMatch(s, sPattern))
         MessageBox.Show("Not a valid Phone Number");

If you look at the above code you will see that i have commented out the pattern for phone number of Bangladesh. If you need to assign phone number of others country please add a regular expression for you phone number. That will work fine.

or If this cause any problem you can simply just modify the text file of you D: drive and put your required information there. but not more that 4 paragraphs and also you have to maintain the  format of the code that is name,email,phone & designation. You will be able to change everything except the mail address, you need to keep mail address at the 2nd paragraph to perform the task properly.

So we have taken inputs from user after validating all the above criteria. Now we need to save the file. I have saved the file as "info.txt" in the D: drive of your computer. When you will run this project it will create two files.

The first one is named "info.txt" for holding information of the user and the second one is named "date.txt"  for checking if the mail has already been sent for the day. 

Now we need to Configure the mailing address of you application.

  1. We need to put mailing address (To) and network credentials.
  2. Mailing address (To) is required to send the mail to a particular address. That is our "To" of the typical mail protocol. Network credentials are required because we needed to send mail to a varieties of mail addresses. That's why we need to go through a mail address that i have access. It maintains the format like below.
var cred = new NetworkCredential(_credentialMail, _credentialPassword);
var mailClient = new SmtpClient("", 587);

It means we are using gmail as smtp client and the network credential that you will provide in _credentialMail & _credentialPassword.

For example: Let we have 3 mail addresses like below.

Address 1:

Address 2: 

Address 3:  Password:12345

Now think we want to send an email to <> from <> So we need to put it like below to work it for this example 

To : 

Network Credential Mail Address:    

Password of the Above Mail Address: 12345

We have saved these information to a text file named CredentialInfo.txt to the D:  drive.  Here you need to know that i have only configured the credentials for gmail. So the Network Credential Mail Address must be a gmail address.

Here is the method that does the work to create the files. 

int CreateFile()
   if (!File.Exists(@"D:\date.txt"))
              using (File.Create(@"D:\date.txt"))
              TextWriter dateS = new StreamWriter(@"D:\date.txt");
              _createfile = 1;
           catch (Exception ex)
              _createfile = 0;
   if (!File.Exists(@"D:\info.txt"))
              using (File.Create(@"D:\info.txt"))
              _createfile = 1;
           catch (Exception ex)
              _createfile = 0;
    if (File.Exists(@"D:\info.txt") && File.Exists(@"D:\date.txt"))
           _createfile = 1;
 return _createfile;

We have done the settings for our application !! Wow . Now we need to send the mail. Here is the code block to send the mail.  

  TextReader tw = new StreamReader(@"D:\CredentialInfo.txt");
  _toMail = tw.ReadLine();
  _credentialMail = tw.ReadLine();
  _credentialPassword = tw.ReadLine();
  message.From = new MailAddress(_mail);
  if (_toMail != null) message.To.Add(_toMail);
  message.Subject = "Entry Time ( " + DateTime.Now.ToShortDateString() + " ) " + DateTime.Now.ToShortTimeString();
  message.BodyEncoding = Encoding.UTF8;
  message.Priority = MailPriority.Normal;
  var cred = new NetworkCredential(_credentialMail, _credentialPassword);
  var mailClient = new SmtpClient("", 587);
  mailClient.EnableSsl = true;
  mailClient.UseDefaultCredentials = false;
  mailClient.Credentials = cred;
  MessageBox.Show("Entry Mail Sent Successfully");

You can see that we are reading the network credential information from the text file. So we need to put valid information in the text file to make it work.

I have also saved the informations to a database. Here is the method to do this.

void insert_database()
    _cmd.Connection = _con;
    _cmd.CommandText = @"INSERT INTO MailInfo (Name,Email,Phone,Designation,MailDate,MailTime) VALUES ('" + _name + "','" + _mail + "','" + _phone + "','" + _des + "','" + DateTime.Now.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')";
 catch (Exception ex)
    MessageBox.Show("Inserting Error in database " + ex);

Here is the database table design:


Second Section

Please follow the steps below to configure the application. 

Step 1: run the project.

Step 2: Settings->  Registration -> fill the text boxes with you information. Here is an example.

Here are some validations that you need to concern about. Follow the U.S. phone format to input the phone number. Example XXX-XXX-XXXX 

Also you need to worry about the mail address format.  

When you will input information properly then the registration success window will appear.

Step 3: Settings-> Configure Mailing Address -> fill the text boxes with you information. Here is an example.


Step 4: go to the D drive of you computer and change the date to the previous date replacing the current date.

Step 5: Press the Send Mail button. The mail will be sent to the address you have entered to the mailling address. You will find a logo  downloaded to your drive. You can also prodive your own logo or your company logo. To do this you need to put the link here. 

if (!File.Exists(@"D:\desme_logo.gif"))
  const string localFilename = @"D:\desme_logo.gif";
  using (var client = new WebClient())
    client.DownloadFile("", localFilename);

Change the link of the dropbox and put your own link. and then put the file name everywhere i used


 I have aslo created a setup project.  You will find everything if you download the project. 

It you want to send mail when the computer stars then you need to do the following. 

Step 1: go to project folder -> open program.cs -> add  

Application.Run(new auto_mail()); replacing Application.Run(new Home());

Note that: There are two seperate projects. Both of them are working. You need to seperate the two projects by replacing  Application.Run(new auto_mail()); with Application.Run(new Home());  or replacing Application.Run(new Home()); with Application.Run(new auto_mail()); To send automail do the last one cause by default i have coded the first one.

Step 2: Build the project -> then rebuild the setup project (automail).

Step 3. Right Click on the setup project -> select install -> Finish the installation.

Step 4: goto your desktop -> you will see automail.exe run the exe.

Step 5: if it promots that you are not registered then register like the procedure i told earlier.

Step 6: close the window -> change the date of the date.txt file as earlier and put the date previous date of today's date -> save the file.

Step 7: run the automail.exe again. then the mail will be shoot now with necessary informations and the informations will be saved in the database  and you will see the window below if everything goes right " />  

If you want to shoot your mail when the computer starts then follow the steps below

Step 1: My computer->right click -> manage. 

Step 2: double click on Task Schedular -> right click Task Schedular Library -> create Task . Then follow the screenshots.


Step 3: Click on Tab  Triggers- > then new . Then select the following as like as the input of the image. Set Active and expired date as you like to trigger the event. and put some delay if you are using modem to connect you computer to internet.

Step 4:  Then click on action tab and do the following. browse the automail.exe on your desktop.

Step 5:  We are done here . You can check the task by right clicking on the task and then Run the task.

Hope the project will reduce your tension coding ... 


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


About the Author

Software Developer Cefalo
Bangladesh Bangladesh

I am Palash Debnath. I have been working on windows technologies since 2008. I started with ASP.NET. Then I moved to Windows Form and from the last year I have been working with Windows 8 app development. My future plan is to work with Windows 10 app development as well. I have completed my Undergraduate from Khulna University of Engineering in Computer Science & Engineering. Now I am working as a Software Engineer at Cefalo on Windows 8 app development.

You may also be interested in...


Comments and Discussions

Questionfound help full. Pin
Wajeed Ali9-Jun-16 23:16
memberWajeed Ali9-Jun-16 23:16 
QuestionMessage Automatically Removed Pin
19-Mar-14 9:08
memberSai Pranad19-Mar-14 9:08 
QuestionQuestion Pin
Member 1047036321-Jan-14 7:30
memberMember 1047036321-Jan-14 7:30 
AnswerRe: Question Pin
dpalash21-Jan-14 21:08
professionaldpalash21-Jan-14 21:08 
Question[My vote of 1] Storing password in plain text? A big no no! Pin
Chris Quinn7-May-13 5:07
memberChris Quinn7-May-13 5:07 
AnswerRe: [My vote of 1] Storing password in plain text? A big no no! Pin
dpalash7-May-13 6:09
professionaldpalash7-May-13 6:09 
GeneralGood article Pin
Sampath Sridhar12-Mar-13 23:13
memberSampath Sridhar12-Mar-13 23:13 
GeneralRe: Good article Pin
dpalash12-Mar-13 23:22
memberdpalash12-Mar-13 23:22 
GeneralMy vote of 5 Pin
Mihai MOGA11-Mar-13 21:48
memberMihai MOGA11-Mar-13 21:48 
GeneralRe: My vote of 5 Pin
dpalash12-Mar-13 8:08
memberdpalash12-Mar-13 8:08 
GeneralMy vote of 5 Pin
Razib Chandra Deb8-Mar-13 7:52
memberRazib Chandra Deb8-Mar-13 7:52 
GeneralRe: My vote of 5 Pin
dpalash8-Mar-13 7:53
memberdpalash8-Mar-13 7:53 
GeneralMy vote of 5 Pin
Md. Selim Reza8-Mar-13 4:20
memberMd. Selim Reza8-Mar-13 4:20 
GeneralMy vote of 5 Pin
Md. Selim Reza8-Mar-13 4:14
memberMd. Selim Reza8-Mar-13 4:14 
GeneralRe: My vote of 5 Pin
dpalash8-Mar-13 7:53
memberdpalash8-Mar-13 7:53 
GeneralMy vote of 5 Pin
Munir Hassan7-Mar-13 22:28
memberMunir Hassan7-Mar-13 22:28 
GeneralRe: My vote of 5 Pin
dpalash8-Mar-13 1:28
memberdpalash8-Mar-13 1:28 
GeneralMy 5 Pin
Shahriar Iqbal Chowdhury/Galib21-Feb-13 1:58
memberShahriar Iqbal Chowdhury/Galib21-Feb-13 1:58 
GeneralRe: My 5 Pin
dpalash21-Feb-13 22:35
memberdpalash21-Feb-13 22:35 
GeneralMy vote of 5 Pin
ridoy18-Feb-13 21:00
memberridoy18-Feb-13 21:00 
GeneralRe: My vote of 5 Pin
dpalash28-Feb-13 16:56
memberdpalash28-Feb-13 16:56 
GeneralMy vote of 5 Pin
Bikash Karmokar17-Feb-13 6:24
memberBikash Karmokar17-Feb-13 6:24 
GeneralRe: My vote of 5 Pin
dpalash17-Feb-13 6:26
memberdpalash17-Feb-13 6:26 
GeneralMy vote of 5 Pin
Maksud Saifullah Pulak17-Feb-13 6:18
memberMaksud Saifullah Pulak17-Feb-13 6:18 
GeneralRe: My vote of 5 Pin
dpalash17-Feb-13 6:21
memberdpalash17-Feb-13 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 10 Feb 2013
Article Copyright 2013 by dpalash
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid