与附件同时发送到多个电子邮件ID时出错

与附件同时发送到多个电子邮件ID时出错

本文介绍了与附件同时发送到多个电子邮件ID时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过以下代码



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





请告诉

问候



pls tell
regards

推荐答案

mailMessage.To =email_to


这篇关于与附件同时发送到多个电子邮件ID时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 11:36