Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
previously i am trying to send mails in separate form
but now i want to send mail automatically in respective email address..

Admin approve/reject documents now i want to add
when admin approve/reject any documents then respective document name and the value which admin select (like approve /reject ) send to his/her mail ... previously i send mail using sepearte form through code is
C#
protected void btnSendMail_Click(object sender, EventArgs e)
    {
        string connStr =
            ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
        SqlConnection mySQLconnection = new SqlConnection(connStr);
        string empId = string.Empty;
        DataTable dt = new DataTable();


        try
        {
            mySQLconnection.Open();
            for (int i = 0; i < Repeateremail.Items.Count; i++)
            {

                CheckBox checkboc =
                 ((CheckBox)Repeateremail.Items[i].FindControl("chkSelect"));
                if (checkboc != null)
                {

                    if (checkboc.Checked == true)
                    {

                        //get Current EMAIL_ID from the DataKey

                        string emailId =
                  ((Label)Repeateremail.Items[i].FindControl("lbl_email")).Text;
                        //write code to send mail
                        SendEmailUsingGmail(emailId);
                        dt.Clear();
                        dt.Dispose();
                    }
                    else if (checkboc.Checked == false)
                    {
                    }
                }
            }

        }


        catch (Exception ex)
        {
            emailsent.Text="Failed";
        }
        finally
        {
            empId = string.Empty;
        }
    }


in above code i send mail through check-boxes when admin check on checkbox and then click on send mail then mail send but now i want when admin approve document then this respective document name and value send in his/her mail .
http://i.stack.imgur.com/9tGh7.png[^]
Posted

1 solution

Hi

You can write a windows service to send mail automatically at a specified interval or time .
Many tutorials are available to create a window service .


Pls refer the following link

http://code.msdn.microsoft.com/windowsdesktop/Notification-Service-A-adf433b7[^]

Pls mark it as answer if it resolves your problem .
 
Share this answer
 
v2
Comments
Diya Ayesa 21-Nov-13 3:47am    
please send me ...i try many times but i can't solve this problem
Vinodh.B 21-Nov-13 4:15am    
Pls see my updated solution with link .
Diya Ayesa 21-Nov-13 4:27am    
i dont understand onstop,onpause,timer_eplased,onshutdown, i dont understand it .... when i approve document there is a button when admin click on submit then mail automatically send to respective mail with table values here is the approve code ...now how i combine this approve code and mail code..i dont understand



protected void Button1_Click(object sender, EventArgs e)
{

string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();

for (int i = 0; i < Repeater2.Items.Count; i++)
{
DropDownList DropDownListcontrol = ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));



SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
cmd.CommandType = CommandType.StoredProcedure;


cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = Convert.ToInt32((DocId.Text));

cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = Convert.ToInt32(DropDownListcontrol.SelectedValue);
cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value = (Session["Login2"]);

cmd.ExecuteNonQuery();
//UPDATE APPPROVEID IN DOCUMENTINFO TABLE
//DMSLIB.Doc myDoc = new DMSLIB.Doc();
//myDoc.MarkDocAs(Convert.ToInt16(DocId.Text), Convert.ToInt32(DropDownListcontrol.SelectedValue));

}

}
else
{
Supvisor.Text = "Error";
}
if (mySQLconnection.State == ConnectionState.Open)
{
mySQLconnection.Close();
}
}
Vinodh.B 21-Nov-13 4:44am    
1)In btnSendMail_Click event Just save the data in DB . DON"T send mail in this event .
Remove this method SendEmailUsingGmail.
2)Create a New Window service project .
3)In the link provide there is a method named timer_elapsed . Here you should do the following
a)Get the mail id's from db whose status is approved/rejected.
b)Loop through the datatable
c)If user is approved send approved mail
d)if user is rejected send rejected mail .

You can schedule this send mail service Hourly/daily/weekly instead user going to screen & sending mails .
Diya Ayesa 21-Nov-13 9:28am    
windows service project?

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