Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
3 days before I have to send email to my customers to remind their travelling timings. in that i am using ASP.NET 2.0, C#.net, and SQL server 2005.and i am using this code..
 
protected void Submit_Click(object sender, EventArgs e)
{
SmtpClient smtpClientUser = new SmtpClient();
MailMessage messageUser = new MailMessage();
messageUser.To.Add(txtemail.Text);
MailAddress fromAddressUser = new MailAddress("sumalatha69@gmail.com");
messageUser.From = fromAddressUser;
messageUser.Subject = "Welcome to HopAroundIndia";
messageUser.IsBodyHtml = true;
messageUser.Body = "Dear " + txttriptitle.Text + ", "
+ txtdestination.Text +"," + txtdescription.Text +"," +txtdate.Text + "," +txtemail.Text;
 
smtpClientUser.Host = "ASPMX.L.GOOGLE.COM";
smtpClientUser.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClientUser.Port = 25;
smtpClientUser.Send(messageUser);
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("Hai_insertnewtripplandetailes", con);
con.Open();
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@userId", Request.Cookies["userId"].Value.ToString());
if (Request.QueryString["TripId"] != null)
{
com.Parameters.Add("@Id", Request.QueryString["TripId"].ToString());
}
com.Parameters.Add("@TripTitle", txttriptitle.Text);
com.Parameters.Add("@Destination", txtdestination.Text);
com.Parameters.Add("@Description", txtdescription.Text);
com.Parameters.Add("@TripStartDate", Convert.ToDateTime(txtdate.Text));
com.Parameters.Add("@Remindme", CheckBox1.Checked);
com.Parameters.Add("@Emailid" ,txtemail.Text);
com.ExecuteNonQuery();
con.Close();
Label1.Text = "Your Trip Plan Created successfully";
ClearControls(Page);
//}
}
 
can u please help me.
i am used sql server 2005
Posted 17-Dec-12 22:20pm
Edited 17-Dec-12 23:07pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use DATEDIFF (Transact-SQL)[^] to find the number of remaining for customer's travel date as of today and retrieve the email addresses for customers whose travel date is 3 days from today.
So your query will have something like this in the where clause
 
WHERE DATEDIFF(DAY, GETDATE(), TravelDate) = 3
Here TravelDate is customer's date of journey.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Create windows service
http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html[^]
 
Sending Email procedure
http://stackoverflow.com/questions/449887/sending-e-mail-using-c-sharp[^]
 
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8[^]
 
include this method in main class in the created window service..
private void ScheduleEmail()
{
//Get the Mailing Information from database and then
//Check the Date (ex: "21/12/2012")
DateTime dtYourDate = Convert.ToDateTime("21/12/2012");
if (DateTime.Now.AddDays(-3).ToShortDateString() == dtYourDate.ToShortDateString())
{
//Call SendMailMethod here;
}
}
 
Call this method on OnElapsedTime event
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
  TraceService("Another entry at "+DateTime.Now);
  ScheduleEmail();
}
  Permalink  
Comments
suma2212 at 20-Dec-12 2:20am
   
Hi i am using ASP.net 2.0 ,C# and sql server 2005
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check this link to create windows service
http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/window_service.aspx
 
// Sample for connection sql
string ConnStrng = "Data Source=localhost\\sqlexpress;Initial Catalog=MembersAccount; Integrated Security=SSPI;";
string updateRec = "INSERT INTO TblMembers(FullName, Iam, Email, Password, BirthMonth, BirthDay, BirthYear) VALUES (@FullName, @Iam, @Email, @Password, @BirthMonth, @BirthDay, @BirthYear)";
 
SqlConnection SqlConn = new SqlConnection(ConnStrng);
 
SqlCommand sqlCmd = new SqlCommand(updateRec,SqlConn);
 
sqlCmd.Parameters.AddWithValue("@FullName", txtfullname.Text);
sqlCmd.Parameters.AddWithValue("@Iam", txtiam.Text);
sqlCmd.Parameters.AddWithValue("@Email", txtemail.Text);
sqlCmd.Parameters.AddWithValue("@Password", txtpassword.Text);
sqlCmd.Parameters.AddWithValue("@BirthMonth", ddlmonth.Text);
sqlCmd.Parameters.AddWithValue("@BirthDay", ddlday.Text);
sqlCmd.Parameters.AddWithValue("@BirthYear", txtyear.Text);
 

try
{
SqlConn.Open();
sqlCmd.ExecuteNonQuery();
lblSecMessage.Text = "Thank you for registering.";
}
catch (Exception ex)
{
lblSecMessage.Text = ex.Message;
}
finally
{
SqlConn.Close();
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

// this by using outlook
 

string emailBody = txtbody.Text;
 
//string[] split = filePath.ToString().Split('\\');
//emailBody.Replace("[Imagefile]", "");
 
Outlook._Application outlookApp = new Outlook.Application();
 
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
 
mailItem.Subject = txtsub.Text;
mailItem.HTMLBody = emailBody;
 
Outlook.Inspector outlookInspector = mailItem.GetInspector;
 
mailItem.To = txtto.Text;
 
mailItem.CC = "chowdary.avula@gmail.com";
 
mailItem.DeferredDeliveryTime = Convert.ToDateTime(dateTimePicker1.Text);
//mailItem.Send();
((Outlook._MailItem)mailItem).Send();
  Permalink  
v2
Comments
suma2212 at 20-Dec-12 5:25am
   
Hi,
 
thanq for ur answer. i have one doubt i am using asp.net 2.0, is it possible to create webservices in asp.net 2.o?
 
please send code for gmail. i am using gmail not outlook
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

First Create a windows service by following steps

[^]
 
write following code in service1.cs file
 
protected override void OnStart(string[] args)
        {
            try
            {
                int iHourIn24HourFormat = Convert.ToInt32(DateTime.Now.ToString("HH"));
                int iCurrentMinutes = DateTime.Now.Minute;
                int iCurrentSecond = DateTime.Now.Second;
 
                int iFirstIntervalGapInHours = 24 - iHourIn24HourFormat;
                eventLog1.WriteEntry("Service Started ---->" + DateTime.Now.ToString());
                objTimer.Interval = (1000 * 60 * 60 * iFirstIntervalGapInHours) + (1000 * 60 * 60 * 2) - (1000 * 60 * iCurrentMinutes) - (1000 * iCurrentSecond); // at Every day 2:00 AM    
                eventLog1.WriteEntry("Interval -> " + objTimer.Interval.ToString());                
 
                objTimer.Enabled = true;
                objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);
                objTimer.Start();
	}
            catch (Exception ex)
            {
 
                eventLog1.WriteEntry("Error: " + ex.Message);
            }            
        }
 
void objTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                eventLog1.WriteEntry("Timer Elapsed ---->" + DateTime.Now.ToString());
 
                objTimer.Interval = 1000 * 60 * 60 * 24; //set interval for every 1 day

                ContinueProcess();
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry("Error: " + ex.Message);
            }
        }
 

private void ContinueProcess()
        {
            HttpWebRequest objHttpWebRequest;
            HttpWebResponse objHttpWebResponse = null;
            try
            {
                objHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.xyz.com/email_Service.aspx");
                objHttpWebRequest.Timeout = 300000;
                objHttpWebRequest.Proxy = null;
                objHttpWebRequest.Method = "Get";
                objHttpWebRequest.ContentLength = 0;
                objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
                Stream objResponseStream = objHttpWebResponse.GetResponseStream();                
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry("ContinueProcess Error: " + ex.Message);
            }
            finally
            {
                if (objHttpWebResponse != null)
                {
                    objHttpWebResponse.Close(); // Close web response Connection
                }
                objHttpWebRequest = null; //To clear up the web request
                objHttpWebResponse = null;//To clear up the web Response
            }
        }
 

In your email_Service.aspx page write following code in page_load event
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
	//Add code to find the list of user to whom you wants to send email.
        }
   }
  Permalink  
Comments
suma2212 at 27-Dec-12 0:27am
   
Hi i am not using asp.net 4.5, i am using asp.net 2.0
Mukund Thakker at 28-Dec-12 1:33am
   
This will work in asp.net 2.0. There is no new feature of 4.5
suma2212 at 16-Jan-13 7:33am
   
how to declare eventlog1,objtimer
Mukund Thakker at 16-Jan-13 8:29am
   
In the Service1, you can drag EventLog from Toolbox.
and for objtimer, please include following namespace.
using System.Timers;
suma2212 at 16-Jan-13 23:58pm
   
Hi thanks for ur help.
my toolbox i didn't get eventlog and objtimer. please explained me.
Mukund Thakker at 17-Jan-13 1:35am
   
Everything is mentioned in following link,
http://www.cjvandyk.com/blog/Articles/How-do-I--Create-a-Windows-Service-application-using-Visual-Studio-2010.aspx
please go through it once again.
suma2212 at 17-Jan-13 2:38am
   
i am using .net 3.5. in that toolbox not shows components ---> eventlog plz give any suggetion to me
suma2212 at 17-Jan-13 4:52am
   
In that above url shows---> vs2010-->newprject-->wondows service.
 
But i am using asp.net and C#.net
 
vs 2008--> new website-->
i am not getting the windows service.
please give me the answer
suma2212 at 17-Jan-13 6:34am
   
Hi i am getting the error in this line
 
objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);
 
does not contain a method for 'Elapsed'. and no extention method for 'Elapsed'.
please tell me the where i did the mistake.
Mukund Thakker at 17-Jan-13 23:35pm
   
It should be
new System.Timers.ElapsedEventHandler(objTimer_Elapsed);
suma2212 at 18-Jan-13 1:12am
   
Hi i did all those things. while run the service i am getting the error like "web services1 service are in local system started and then stopped. and some services stop automatically if they are not in use by other services or programs".
 
eventviewer--->custom views ---> administrative events--> i am getting some error
while click the error i am getting this message.
 
"Service cannot be started. System.ArgumentException: Source property was not set before writing to the event log.
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message)
at sendingmail.Service1.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)"
 
please help me
Mukund Thakker at 18-Jan-13 4:13am
   
You have to create setup file, and then run setup file. after that from windows services find installed service and start service by right clicking on it.
-----------------------------------------------------------------------
Do not forget to mark as answer if it really helps you...
suma2212 at 21-Jan-13 23:48pm
   
Hi i am getting the error.
 
objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);
 
even i add new System.Timers.ElapsedEventHandler(objTimer_Elapsed); to that line i am getting the same error in "objtimer.Elapsed +".
 
please help me.....
Mukund Thakker at 22-Jan-13 0:23am
   
Please check below url,
 
http://www.google.com/#hl=en&tbo=d&site=&source=hp&q=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&oq=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&gs_l=hp.12...2789.2789.0.4290.1.1.0.0.0.0.0.0..0.0.les%3B..0.0...1c.1.d6zqYLsSW_0&bav=on.2,or.r_gc.r_pw.&bvm=bv.41248874,d.cGE&fp=24b326c37e5c7d66&biw=1467&bih=664
 

http://www.dotnetfunda.com/forums/thread8099-error-in-window-service-while-starting.aspx
 
Mukund Thakker at 22-Jan-13 0:26am
   
Please check following url,
 
http://www.dotnetfunda.com/forums/thread8099-error-in-window-service-while-starting.aspx
 
http://www.google.com/#hl=en&tbo=d&site=&source=hp&q=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&oq=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&gs_l=hp.12...2789.2789.0.4290.1.1.0.0.0.0.0.0..0.0.les%3B..0.0...1c.1.d6zqYLsSW_0&bav=on.2,or.r_gc.r_pw.&bvm=bv.41248874,d.cGE&fp=24b326c37e5c7d66&biw=1467&bih=664
Mukund Thakker at 22-Jan-13 0:26am
   
Please check following url,
 
http://www.dotnetfunda.com/forums/thread8099-error-in-window-service-while-starting.aspx
 
http://www.google.com/#hl=en&tbo=d&site=&source=hp&q=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&oq=Service+cannot+be+started.+System.ArgumentException:+Source+property+was+not+set+before+writing+to+the+event+log.+at+System.Diagnostics.EventLog.WriteEntry%28String+message%2C+EventLogEntryType+type%2C+Int32+eventID%2C+Int16+category&gs_l=hp.12...2789.2789.0.4290.1.1.0.0.0.0.0.0..0.0.les%3B..0.0...1c.1.d6zqYLsSW_0&bav=on.2,or.r_gc.r_pw.&bvm=bv.41248874,d.cGE&fp=24b326c37e5c7d66&biw=1467&bih=664
suma2212 at 22-Jan-13 0:55am
   
hi, can I send an email before 3 days to user with out using window services?
Mukund Thakker at 22-Jan-13 1:59am
   
you can add code to send email in your website home page, page_load, if you are sure that home page would be visited everyday.

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 20 Dec 2012
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