Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i tried following code

C#
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<br />
smtpClient.Send(mailMessage); 


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

1 solution

You are missing
C#
mailMessage.To =email_to
 
Share this answer
 
Comments
shivani 2013 1-Feb-13 7:39am    
i have used foreach and an arraylist which it will take the addresses too whom to send..
Santhosh Kumar Jayaraman 1-Feb-13 7:40am    
But where you assigning it to mailmessage.to? Dont you see that you are missing it?
shivani 2013 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900