参数'解决'不能为空字符串 [英] The parameter 'addresses' cannot be an empty string

查看:2339
本文介绍了参数'解决'不能为空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在asp.net中发送邮件
当管理员批准/拒绝的文档,然后将数据保存到数据库中
像这样

 的SeqNo的DocID ApproveID ApproveBy
82 20 3约翰·
83 21 1约翰
84 18 2凯蒂
85 19 1 EMEL

现在我发邮件也
当管理员点击按钮,然后邮件发送给相应的电子邮件ID
这样我显示报时表

 可采用DocName的DocID USEREMAIL Uplaodedfile的DocType deptype定义ApproveID
 1 ABC def.pdf abcdef@gmail.com PDF小时(在此我设置下拉值(批准/拒绝/待定)

这是按钮code

 保护无效的button1_Click(对象发件人,EventArgs的发送)
{
   字符串connStr = ConfigurationManager.ConnectionStrings [mydms]的ConnectionString。
   的SqlConnection的MySqlConnection =新的SqlConnection(connStr);
   如果(mySQLconnection.State == ConnectionState.Closed)
   {
       mySQLconnection.Open();
       的for(int i = 0; I< Repeater2.Items.Count;我++)
       {
           DropDownList的DropDownListcontrol =((DropDownList的)Repeater2.Items [I] .FindControl(DropDownList4));
           标签的docID =((标签)Repeater2.Items [I] .FindControl(DOCID));           CMD的SqlCommand =新的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的=
           (会话[Login2身份]);
            尝试
            {
                cmd.ExecuteNonQuery();
                字符串EMAILID =((标签)Repeater2.Items [I] .FindControl(Label2的))文本。
                SendEmailUsingGmail(EMAILID);
             }
             赶上(异常前)
             {
                 Supvisor.Text =(ex.Message);
             }
             cmd.ExecuteNonQuery();
             // UPDATE APPPROVEID IN DOCUMENTINFO表
             //DMSLIB.Doc myDoc =新DMSLIB.Doc();
             //myDoc.MarkDocAs(Convert.ToInt16(DocId.Text)
             Convert.ToInt32(DropDownListcontrol.SelectedValue));
        }    }
    其他
    {
         Supvisor.Text =错误;
    }
    如果(mySQLconnection.State == ConnectionState.Open)
    {
         mySQLconnection.Close();
    }
 }    私人无效SendEmailUsingGmail(字符串toEmailAddress)
    {
        尝试
        {
            SmtpClient SMTP =新SmtpClient();
            smtp.Credentials =新的NetworkCredential(keysketyyyy@gmail.com
             sdsdasd);
            smtp.Port = 587;
            smtp.Host =smtp.gmail.com;
            smtp.EnableSsl = TRUE;
            消息MAILMESSAGE新= MAILMESSAGE();
            message.From =新的MailAddress(keysketyyy@gmail.com);
            message.To.Add(toEmailAddress);
            message.Subject =在这里写下你的电子邮件的主题;
            message.Body =这里写电子邮件的内容;
            smtp.Send(消息);
        }
        赶上(异常前)
        {
            的Response.Write(发生错误:+ ex.Message.ToString());
        }
    }

在此行中发生

错误,当我设置一个断点

 赶上(异常前)
        {
            的Response.Write(发生错误:+ ex.Message.ToString());
        }

错误

 参数地址不能为空字符串。
     参数名:地址


解决方案

尝试

  message.To.Add(新MailAddress(toEmailAddress));

和验证变量toEmailAddress的内容。

i try to send mail in asp.net when admin approve /reject document then data save into database like this

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

 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

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

 catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }

error

The parameter 'addresses' cannot be an empty string.
     Parameter name: addresses

解决方案

try

message.To.Add(New MailAddress(toEmailAddress));

and verify the content of the variable "toEmailAddress".

这篇关于参数'解决'不能为空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆