asp.net - 无法使用 Asp.Net 通过 SMTP 发送邮件

标签 asp.net

单击“发送”按钮后,我需要一次向 60 到 100 名学生发送邮件。如果我有 6 到 7 个学生,它工作得很好,但是当我开始发送给 60 个学生时,我的代码显示以下错误

系统存储空间不足。服务器响应是:每个连接的电子邮件过多。

这是我的代码

protected void btnsend_Click(object sender, EventArgs e) {

     if (drptopics.SelectedValue == "-1")
            {
                Response.Write(@"<script language='javascript'>alert('Please select one Topic');</script>");
            }


     else

     {

    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Data Source=xxxx; User Id=sa; Password=xxxx; Initial Catalog=xxxx; Integrated Security=SSPI;";
    conn.Open();


    SqlCommand cmd = new SqlCommand();
    cmd.Connection = conn;
    cmd.CommandText = "select EMail_1 from Student_Info where Branch_Code='ap' and Student_ID in(select Student_ID from Admissions where Branch_Code='ap' and Batch_ID='" + txtbatchid.Text + "')";
    cmd.CommandType = CommandType.Text;

    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.SelectCommand = cmd;
    DataSet ds = new DataSet();
    da.Fill(ds);




    if (ds.Tables[0].Rows[0][0] != null)
    {
        int count = ds.Tables[0].Rows.Count;


        for (int i = 0; i < count; i++)
        {

            MailMessage mm = new MailMessage();
            mm.To.Add(new MailAddress(ds.Tables[0].Rows[i][0].ToString()));
            mm.From = new MailAddress("xxxxx@abc.com");
            mm.Subject = "SMS and Interview Questions of Oracle 11g DBA";
            mm.IsBodyHtml = true;





            //Day 1 Architecture 1
             if (drptopics.SelectedValue == "1")
            {
                Attachment attachment1 = new Attachment(Server.MapPath("~/Oracle 11g DBA/Day 1/Architecture-1-I.doc")); //create the attachment
                mm.Attachments.Add(attachment1);
                Attachment attachment2 = new Attachment(Server.MapPath("~/Oracle 11g DBA/Day 1/Architecture1-S.doc")); //create the attachment
                mm.Attachments.Add(attachment2);

            }


            //Day 2 Architecture 2
            else if (drptopics.SelectedValue == "2")
            {
                Attachment attachment1 = new Attachment(Server.MapPath("~/Oracle 11g DBA/Day 2/Architecture-2-I.doc")); //create the attachment
                mm.Attachments.Add(attachment1);
                Attachment attachment2 = new Attachment(Server.MapPath("~/Oracle 11g DBA/Day 2/Architecture2-S.doc")); //create the attachment
                mm.Attachments.Add(attachment2);
            }

             mm.Body = "<html><head><body><h1>Thank you for choosing Wilshire</h1><br><b>Team Wilshire<b></body></head></html>";
            SmtpClient s = new SmtpClient("smtp.net4india.com");
            s.Send(mm);


        }

    }

请告诉我解决方案......................................

最佳答案

SmtpClient.SendAsync() 可能会导致其他问题(SMTP 服务器设置每分钟最大邮件数以避免垃圾邮件)!

由于邮件是相同的,解决方案是一封邮件,所有收件人都是隐藏收件人(Bcc)!

MailMessage mm = new MailMessage();

for (int i = 0; i < count; i++)
{
  mm.Bcc.Add(new MailAddress(ds.Tables[0].Rows[i][0].ToString()));
}
mm.To.Add(new MailAddress("xxxxx@abc.com");
mm.From = new MailAddress("xxxxx@abc.com");
mm.Subject = "SMS and Interview Questions of Oracle 11g DBA";

....

SmtpClient s = new SmtpClient("smtp.net4india.com");
s.Send(mm);

关于asp.net - 无法使用 Asp.Net 通过 SMTP 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854590/

相关文章:

asp.net - css、div 和 asp 的不透明度问题 :Image

javascript - ajax发送二维数组到操作方法错误 - asp.net mvc

c# - 在代码中的什么地方应该保存不变的数据?

asp.net - 我可以通过 SSL 使用单独的 web.config 文件吗?

asp.net - .Net Core Web API 无法将路由添加到 Controller 操作

jquery - 与 asp.net 表单一起使用的最佳工具提示?

asp.net - 限制 ASP.NET Core Controller 操作中接受的媒体类型

javascript - Jquery 获取表 gridview 中所有选中行的值

asp.net - .Net System.Mail.Message添加多个 "To"地址

jquery - 使用 jQuery 检索服务器控件的 ID