By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

send email automatically in button click

P: 5
previously i am trying to send mails in separate form like this
http://i.stack.imgur.com/klLVx.png

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



Expand|Select|Wrap|Line Numbers
  1. protected void btnSendMail_Click(object sender, EventArgs e)
  2.     {
  3.         string connStr =
  4.             ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
  5.         SqlConnection mySQLconnection = new SqlConnection(connStr);
  6.         string empId = string.Empty;
  7.         DataTable dt = new DataTable();
  8.  
  9.  
  10.         try
  11.         {
  12.             mySQLconnection.Open();
  13.             for (int i = 0; i < Repeateremail.Items.Count; i++)
  14.             {
  15.  
  16.                 CheckBox checkboc =
  17.                  ((CheckBox)Repeateremail.Items[i].FindControl("chkSelect"));
  18.                 if (checkboc != null)
  19.                 {
  20.  
  21.                     if (checkboc.Checked == true)
  22.                     {
  23.  
  24.                         //get Current EMAIL_ID from the DataKey
  25.  
  26.                         string emailId =
  27.                   ((Label)Repeateremail.Items[i].FindControl("lbl_email")).Text;
  28.                         //write code to send mail
  29.                         SendEmailUsingGmail(emailId);
  30.                         dt.Clear();
  31.                         dt.Dispose();
  32.                     }
  33.                     else if (checkboc.Checked == false)
  34.                     {
  35.                     }
  36.                 }
  37.             }
  38.  
  39.         }
  40.  
  41.  
  42.         catch (Exception ex)
  43.         {
  44.             emailsent.Text="Failed";
  45.         }
  46.         finally
  47.         {
  48.             empId = string.Empty;
  49.         }
  50.     }
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 .

now i want to do this

http://i.stack.imgur.com/9tGh7.png

here is approve button code

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.                 string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
  5.               SqlConnection mySQLconnection = new SqlConnection(connStr);
  6.               if (mySQLconnection.State == ConnectionState.Closed)
  7.               {
  8.                   mySQLconnection.Open();
  9.  
  10.                   for (int i = 0; i < Repeater2.Items.Count; i++)
  11.                   {
  12.                       DropDownList DropDownListcontrol = ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
  13.                       Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));
  14.  
  15.  
  16.  
  17.                       SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
  18.                       cmd.CommandType = CommandType.StoredProcedure;
  19.  
  20.  
  21.                       cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = Convert.ToInt32((DocId.Text));
  22.  
  23.                       cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = Convert.ToInt32(DropDownListcontrol.SelectedValue);
  24.                       cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value = (Session["Login2"]);
  25.  
  26.                       cmd.ExecuteNonQuery();
  27.                       //UPDATE APPPROVEID IN DOCUMENTINFO TABLE
  28.                       //DMSLIB.Doc myDoc = new DMSLIB.Doc();
  29.                       //myDoc.MarkDocAs(Convert.ToInt16(DocId.Text), Convert.ToInt32(DropDownListcontrol.SelectedValue));
  30.  
  31.                   }
  32.  
  33.               }
  34.               else
  35.               {
  36.                   Supvisor.Text = "Error";
  37.               }
  38.               if (mySQLconnection.State == ConnectionState.Open)
  39.               {
  40.                   mySQLconnection.Close();
  41.               }
  42.                     }

i want to do both in one button ... i done approve task now i want to send email when admin click on button then also send mail
Nov 21 '13 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
What?

You want to send an email and it seems like you know how to do that because you haven't posted any code for the SendEmailUsingGmail method...nor have you stated that you are seeing errors.

While you are looping through your retrieved items from the repeater....and after you have successfully saved the action information to your database....why don't you send the email using the SendEmailUsingGmail method?

-Frinny
Nov 26 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.