Click here to Skip to main content
11,712,727 members (79,081 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 .NET4 ASP.NET4.0
i tried following code

protected void btnSendEmail_Click(object sender, EventArgs e)
   {
       if (txtemailfrom.Text == "" || txtsubject.Text == "" || txtbody.Text == "")
       {
 
           lblmail.Text = "Please fill all mandatory fields.";
 
           lblmail.Visible = true;
 
           return;
 
       }
 
       SmtpClient smtpClient = new SmtpClient();
 
       MailMessage mailMessage = new MailMessage();
 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString);
 
       ArrayList list_emails = new ArrayList();
 
       int i = 0;
 
       string email;
 
       con.Open();
 
       SqlCommand cmd = new SqlCommand("Select EmailId from Employees", con);
 
       SqlDataReader read_Email = cmd.ExecuteReader();
 
       while (read_Email.Read())
       {
 
           email = read_Email.GetValue(i).ToString();
 
           list_emails.Add(email);     //Add email to a arraylist

           i = i + 1 - 1;
 
       }
 
       read_Email.Close();
 
       con.Close();  //Close connection

       foreach (string email_to in list_emails)
       {
 
           if (fileAttachement.PostedFile != null)
           {
 
               HttpPostedFile AttachFile = fileAttachement.PostedFile;
 
               int AttachFileLength = AttachFile.ContentLength;
 
               if (AttachFileLength > 0)
               {
                   string FileName = Path.GetFileName(fileAttachement.PostedFile.FileName);
 
               }
 
           }
 
           MailAddress fromAddress = new MailAddress(txtemailfrom.Text);
 
           mailMessage.From = fromAddress;
 
           mailMessage.Subject = txtsubject.Text;
 
           mailMessage.Body = txtbody.Text;
 
           string Body = "";
 
           Body += '\n' + "From:" + txtemailfrom.Text;
 
           Body += '\n' + "";
 
           Body += '\n' + "Subject:" + txtsubject.Text;
 
           Body += '\n' + "";
 
           Body += '\n' + txtbody.Text;
 
           mailMessage.IsBodyHtml = true;
 
           mailMessage.Body = Body;
 
           smtpClient.Host = "localhost";
           smtpClient.Credentials = new System.Net.NetworkCredential("username", "pwd");
 
           smtpClient.Send(mailMessage);
 
           lblmail.Visible = true;
 
           lblmail.Text = "Your mail has been sent successfully";
 
           tblemail.Visible = true;
 
       }
 
       txtemailfrom.Text = "";
 
       txtsubject.Text = "";
 
       txtbody.Text = "";
 
   }

//getting error "no receipt" on
smtpClient.Send(mailMessage);


pls tell
regards
Posted 1-Feb-13 1:22am
v3
Comments
JemiM at 1-Feb-13 7:26am
   
I think the recipient address you are sending is not correct format.
shivani 2013 at 1-Feb-13 7:41am
   
its in correct format

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are missing
mailMessage.To =email_to
  Permalink  
Comments
shivani 2013 at 1-Feb-13 7:39am
   
i have used foreach and an arraylist which it will take the addresses too whom to send..
Santhosh Kumar J at 1-Feb-13 7:40am
   
But where you assigning it to mailmessage.to? Dont you see that you are missing it?
shivani 2013 at 2-Feb-13 5:25am
   
i did what u said .i am getting an error after sending mail on
mailMessage.To.Add(email_to); that " The parameter 'addresses' cannot be an empty string.
Parameter name: addresses " and the message has been said to the persons to whom i send mail but without attachment.....pls resolve
regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100