0
@Nikunj
Thank you very much!! one last question, how would i use the for loop checking grid side and that what i would be more familar!
thanks!!!
0
There is 2 way u can check it grid side using forloop if u r cell of grid contain 200 then send mail.
or database side u can use like this
and do something like this ... and return value from db and based on return value send email.
- DECLARE @site_value INT;
- SET @site_value = 0;
-
- WHILE @site_value = 200
- BEGIN
- PRINT 'Send Email';
- SET @site_value = @site_value + 1;
- END;
-
- PRINT 'Done WHILE LOOP';
- GO
0
@Nikunj
I have the email part working just usnure how to use a 'for loop' through a database to see if 200 is any value in the table.
0
Ok If you want to send email if one of the below materials goes under 200.
then Simply, you can check every record using any looping such as foreach and etc within this your table if you found then call created function of mail else do nothing .
0
@Nikunj
yes if one of the below materials goes under 200
0
Hello Carol,
can u know specific event ?? i meam when you want to send email ???
Actually as per u r requirement u should check this evrytime user login and when page load first time simply after login in page load event you can check wather mail is send today for this user ? if no then call this function else do nothing.
For this you can add one additional col in database with name "IsSend" with datatype BIT.
0
Hi Carol,
To send email at specific time. We have many options which runs in background and send email.
1. Create Window Service
http://www.c-sharpcorner.com/UploadFile/ee01e6/create-windows-service-and-send-mail-daily-on-fixed-time-usi575/
2. Create SQL Job which
https://www.howtogeek.com/howto/database/sending-automated-job-email-notifications-in-sql-server-with-smtp/
0
@Nikunj
where does the c# code go? on page load on the Stock web form?
thank you!!
0
Hi Carol,
You can try this way. in my case i send mail on specific date such as birthdate. you can modifay this code and can be use as per u r requirement .
i hope this is may helpful to u.
App.Config
- <appSettings>
- <add key ="Mode" value ="Daily" />
- <add key ="IntervalMinutes" value ="1" />
- <add key ="ScheduledTime" value ="17:43" />
- </appSettings>
- <connectionStrings>
- <add name="constr" connectionString="Data Source=.\SQL2008R2;Initial Catalog=StudentsDB;integrated security=true" />
- </connectionStrings>
C# Code :
- try
- {
- DataTable dt = new DataTable();
- string query = "SELECT Name, Email FROM Students WHERE DATEPART(DAY, BirthDate) = @Day AND DATEPART(MONTH, BirthDate) = @Month";
- string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand(query))
- {
- cmd.Connection = con;
- cmd.Parameters.AddWithValue("@Day", DateTime.Today.Day);
- cmd.Parameters.AddWithValue("@Month", DateTime.Today.Month);
- using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
- {
- sda.Fill(dt);
- }
- }
- }
- foreach(DataRow row in dt.Rows)
- {
- string name = row["Name"].ToString();
- string email = row["Email"].ToString();
- WriteToFile("Trying to send email to: " + name + " " + email);
-
- using (MailMessage mm = new MailMessage("sender@gmail.com", email))
- {
- mm.Subject = "Birthday Greetings";
- mm.Body = string.Format("Happy Birthday {0}
Many happy returns of the day.", name); -
- mm.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient();
- smtp.Host = "smtp.gmail.com";
- smtp.EnableSsl = true;
- System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
- credentials.UserName = "sender@gmail.com";
- credentials.Password = "";
- smtp.UseDefaultCredentials = true;
- smtp.Credentials = credentials;
- smtp.Port = 587;
- smtp.Send(mm);
- WriteToFile("Email sent successfully to: " + name + " " + email);
- }
- }
- this.ScheduleService();
- }
- catch (Exception ex)
- {
- WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace);
-
-
- using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService"))
- {
- serviceController.Stop();
- }
- }
