Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
2.23/5 (3 votes)
See more:
Hi all,

I got a given below error in my code below, please have you look at my code below and let me know why its happened in my code behind.

error: No overload for method 'Send' takes '5' arguments
C#
protected void ImgBtnSubmit_Click(object sender, ImageClickEventArgs e)
  {
      try
      {

          string toadd = "info@abc.co.uk";
          var fromAddress = "info@abc.co.uk";

          var toAddress = toadd;
          const string fromPassword = "abc";
          string subject = "Contact";

          string bcc = "xyz@abc.co.uk";
          string body = "<table border=1><tr><td> Name </td><td>" + txtname.Text + "</td></tr>" +
                  "<tr><td> Telephone </td><td> " + txttel.Text + "</td></tr>" +
                  "<tr><td> Mobile </td><td> " + txtmobile.Text + "</td></tr>" +
                  "<tr><td> Email </td><td> " + txtemail.Text + "</td></tr>" +
                  "<tr><td> Query </td><td> " + txtquery.Text + "</td></tr></table>";

          var smtp = new System.Net.Mail.SmtpClient();
          {
              smtp.Host = "mail.abc.co.uk";
              smtp.Port = 25;
              smtp.EnableSsl = false;
              smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
              smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
              smtp.Timeout = 20000;
          }
          smtp.Send(fromAddress,toAddress,bcc, subject,body);  // here am getting above mentioned error

          Response.Redirect("replycontact.aspx");

          txtname.Text = "";
          txttel.Text = "";
          txtmobile.Text = "";
          txtemail.Text = "";
          txtquery.Text = "";
      }
      catch (Exception) { }
  }

thanks in advance.
Posted
Updated 29-Nov-13 0:32am
v2

The error is pretty explicit: "No overload for method 'Send' takes '5' arguments"
And it's true: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.send(v=vs.110).aspx[^] there is one with one parameter, and one with four. There is no method which takes a bcc string.
 
Share this answer
 
please try with MailMessage object and smtp.Send will not take 5 argument.

C#
protected void ImgBtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {

            string toadd = "info@abc.co.uk";
            var fromAddress = "info@abc.co.uk";

            var toAddress = toadd;
            const string fromPassword = "abc";
            string subject = "Contact";

            string bcc = "xyz@abc.co.uk";
            string body = "<table border=1><tr><td> Name </td><td>" + txtname.Text + "</td></tr>" +
                    "<tr><td> Telephone </td><td> " + txttel.Text + "</td></tr>" +
                    "<tr><td> Mobile </td><td> " + txtmobile.Text + "</td></tr>" +
                    "<tr><td> Email </td><td> " + txtemail.Text + "</td></tr>" +
                    "<tr><td> Query </td><td> " + txtquery.Text + "</td></tr></table>";

            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "mail.abc.co.uk";
                smtp.Port = 25;
                smtp.EnableSsl = false;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout = 20000;
            }
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(fromAddress);
            msg.To.Add(new MailAddress(toAddress));
            msg.Bcc.Add(new MailAddress(bcc));
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;

            smtp.Send(msg); 

            Response.Redirect("replycontact.aspx");

            txtname.Text = "";
            txttel.Text = "";
            txtmobile.Text = "";
            txtemail.Text = "";
            txtquery.Text = "";
        }
        catch (Exception) { }
    }
 
Share this answer
 
v4
The answer is simple:

SmtpClient has exactly two Send methods. The first takes simply a MailMessage instance and the second takes exactly four string parameters.

Look here: SmtpClient.Send Method[^].

Being able to read is a good thing, use it every day!

Cheers!
 
Share this answer
 

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