Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用System.Net.Mail发送电子邮件_C#_Asp.net - Fatal编程技术网

C# 使用System.Net.Mail发送电子邮件

C# 使用System.Net.Mail发送电子邮件,c#,asp.net,C#,Asp.net,我想用System.Net.Mail发送电子邮件 我使用这个代码 string[] emails = Email.Split(','); MailMessage message = new MailMessage(); message.From = new MailAddress("doc@mysite.net"); foreach (var em in emails) message.To.Add(new MailAddress(em)); message.Subject =

我想用System.Net.Mail发送电子邮件

我使用这个代码

 string[] emails = Email.Split(',');
 MailMessage message = new MailMessage();
 message.From = new MailAddress("doc@mysite.net");
 foreach (var em in emails)
   message.To.Add(new MailAddress(em));
 message.Subject = "ثبت مدارک جدید";
 message.Body = DNameTextBox.Text + Environment.NewLine + DMobileTextBox.Text + 
  Environment.NewLine + DEmailTextBox.Text + Environment.NewLine 
  + DsubjectTextBox.Text + Environment.NewLine + DDescTextBox.Text;
 {
     HttpFileCollection hfc = Request.Files;
     for (int i = 0; i <= hfc.Count - 1; i++)    // CHECK THE FILE COUNT.
      {
        HttpPostedFile hpf = hfc[i];
        if (hpf.ContentLength > 0)
          message.Attachments.Add(
            new Attachment(hpf.InputStream, Path.GetFileName(hpf.FileName))
          );
       }
      }

      SmtpClient smtp = new SmtpClient("mail.site.com", 25);

      //to authenticate we set the username and password properites on the SmtpClient
      smtp.Credentials = new NetworkCredential("doc@mysite.net", "000");
      smtp.Send(message);
它发送了电子邮件,但我的问题是它发送了20封电子邮件


为什么smtp.Sendmessage发送多封电子邮件?

这是因为您在地址中添加了多个地址。因此,它将向所有收件人的电子邮件地址发送电子邮件

请参阅下面的代码

 foreach (var em in emails)
   message.To.Add(new MailAddress(em));

您可以根据电子邮件添加收件人。拆分','。电子邮件里有什么?可能有二十个以逗号分隔的地址吗?是的,我有两封电子邮件。sms@mysite.com,mysite@gmail.comHave您在smtp上设置了断点。是否发送?它被击中了多少次。如果你的电子邮件中只有两个2地址,那么它可能会被点击十次。点击时间为5秒。好的,它在5秒内到达,但有多少次?我想发送电子邮件到2个邮箱地址。当检查邮箱时,我每2秒收到一封新邮件。发送邮件时收到20封电子邮件。首先,你的英语和要求不明确。还有一件事我不知道你为什么给答案打负分。我只是想帮你。查看您发送的任何收件人,如果您将其发送给两个收件人,它将发送两封电子邮件。现在检查多次调用SMTP.Send。是,但如果您的邮件中有两个地址,请选择“发送”。部分它肯定会发送两封电子邮件。因为这就是电子邮件在gmail中的工作方式,若你们在字段中输入两个电子邮件地址,那个么它将以相同的方式向这两个电子邮件地址发送电子邮件。我不知道你为什么不理解这个简单的基本问题。