Click here to Skip to main content
15,887,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i try to send mail in asp.net when admin approve /reject document then data save into database like this

HTML
SeqNo DocID ApproveID ApproveBy
82  20  3   john
83  21  1   john
84  18  2   kety
85  19  1   emel


now i send email also when admin click on button then email send to respective email id like this i show in repeater table

SQL
DocID DocName Uplaodedfile UserEmail       DocType DepType ApproveID
1      ABC      def.pdf    abcdef@gmail.com  pdf      hr      (In this i set dropdown values are (approve/reject/pending)


and this is button code
C#
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"]);
                  try
                  {
                      cmd.ExecuteNonQuery();
                      string emailId = 
              ((Label)Repeater2.Items[i].FindControl("Label2")).Text;
                      SendEmailUsingGmail(emailId);
                  }
                  catch (Exception ex)
                  {
                      Supvisor.Text=(ex.Message);
                  }
                  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();
          }
                }
    private void SendEmailUsingGmail(string toEmailAddress)
    {
        try
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new NetworkCredential("keysketyyyy@gmail.com", 
             "sdsdasd");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            MailMessage message = new MailMessage();
            message.From = new MailAddress("keysketyyy@gmail.com");
            message.To.Add(toEmailAddress);
            message.Subject = "Write your email subject here";
            message.Body = "write the content of the email here";
            smtp.Send(message);
        }
        catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }
    }


error occured in this line when i set a breakpoint
C#
catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }


CSS
error

The parameter 'addresses' cannot be an empty string.
     Parameter name: addresses
Posted
Comments
Richard C Bishop 21-Nov-13 13:54pm    
Does your stored procedure expect a parameter of "addresses"?

1 solution

Add a breakpoint and check the value of your toEmailAddress. Looks like that's blank.
 
Share this answer
 
Comments
Diya Ayesa 21-Nov-13 15:33pm    
yes it is blank like this ""
Diya Ayesa 21-Nov-13 15:36pm    
take a look below code ..
protected void Button1_Click(object sender, EventArgs e)
{

string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
string empId = string.Empty;
DataTable dt = new DataTable();

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();

try
{

if (DropDownListcontrol != null)
{

if (DropDownListcontrol.SelectedValue == "1")
{

//get Current EMAIL_ID from the DataKey

string emailId = ((Label)Repeater2.Items[i].FindControl("Label2")).Text;
//write code to send mail
SendEmailUsingGmail(emailId);
dt.Clear();
dt.Dispose();
}
else if (DropDownListcontrol.SelectedValue == "3")
{
}
}
}
catch (Exception ex)
{
Supvisor.Text = "Failed";
}
finally
{
empId = string.Empty;
}






//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();
}

}
Diya Ayesa 21-Nov-13 15:37pm    
i try to send mail but when i try above code it can not be show any error and also mail not send to respective email id
woopsydoozy 21-Nov-13 16:56pm    
Don't know why the correct answer got voted down, but whatever. If you're not getting any error as you step through, then likely the mail is going out and getting stuck somewhere in the network. As a starting point, if you've got virus protection on your machine, that may be blocking it--you might see it blocked in the virus protection's log. If it got off your machine and didn't make it to the target, you might need a network admin's assistance--you're beyond a software problem at that point. I'd start by trying a local SMTP server and see if you can make it work there.

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