Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to develop Email sending application....

i have tried coding like this


C#
public void sendMail(string toList, string fromlist, string ccList, string subject, string body)
  {
      MailMessage message = new MailMessage();
      SmtpClient smtpClient = new SmtpClient();
      MailAddress fromAddress = new MailAddress(fromlist);
      message.From = fromAddress;
      message.To.Add(toList);
      if (ccList != null && ccList != string.Empty)
      {
          message.CC.Add(ccList);
      }
      message.Subject = subject;
      message.IsBodyHtml = true;
      message.Body = body;
      smtpClient.Host = "127.0.0.1";
      smtpClient.Port = 25;
      smtpClient.UseDefaultCredentials = true;
      smtpClient.Credentials = new System.Net.NetworkCredential(txtfromadd.Text, txtpwd.Text);
      smtpClient.Send(message);

  }

  protected void btnSubmit_Click(object sender, EventArgs e)
  {
      //string fromadd = txtfromadd.Text;
      string tocc = "suguna@cavintek.com";
      sendMail(txtToAddress.Text, txtfromadd.Text, tocc, txtSubject.Text, txtContent.Text);
  }

but i got error in this line smtpClient.Send(message);

iI want to change any settings ?...give ur sugeestions?
Posted
Updated 24-Aug-11 19:38pm
v3
Comments
Uday P.Singh 25-Aug-11 1:55am    
where is you smtp server name? Here you are trying to send mail from localhost, change it to smtp server name.

1 solution

You dont have to make any changes in your config as you are providing all the credentials in your code itself. Just make sure that the credentials given by you are correct, i mean to say the IP address and the user name , password.
 
Share this answer
 
v3
Comments
suryaswathi 25-Aug-11 2:47am    
A socket operation was attempted to an unreachable network 127.0.0.1:25

i give correctly..i gave anju@yahoo.com ,****** like that oly credentials i gave i got sending mail failed
sujit0761 25-Aug-11 3:37am    
Your IP configuration for sending mail is not correct. Please refer your SYSdamin team for correct IP address
suryaswathi 25-Aug-11 5:45am    
my Ip address is 127.0.0.1

my port no is : 25

that only showing like that ..127.0.0.1:25

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