多电子邮件发送

发布于 2024-09-08 17:54:17 字数 1715 浏览 7 评论 0原文

可能的重复:
将电子邮件发送到多个地址/收件人

我正在使用以下代码,并且它只发送一封电子邮件 - 我必须发送多封电子邮件。

为了获取多封电子邮件,我使用:

string connectionString = ConfigurationManager.ConnectionStrings["email_data"].ConnectionString;
        OleDbConnection con100 = new OleDbConnection(connectionString);
        OleDbCommand cmd100 = new OleDbCommand("select top 3 emails  from bulk_tbl", con100);
        OleDbDataAdapter da100 = new OleDbDataAdapter(cmd100);
        DataSet ds100 = new DataSet();
        da100.Fill(ds100);
        {
            for (int i = 0; i < ds100.Tables[0].Rows.Count; i++)
            //try
            {
                string all_emails = ds100.Tables[0].Rows[i][0].ToString();
                {
                    string allmail = all_emails + ";";
                    Session.Add("ad_emails",allmail);
                    Response.Write(Session["ad_emails"]);
                    send_mail();
                }
            }
        }
    }

为了发送一封电子邮件,我使用

    string sendto = Session["ad_emails"].ToString();

    MailMessage message = new MailMessage("[email protected]", sendto, "subject", "body");
    SmtpClient emailClient = new SmtpClient("mail.smtp.com");
    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("abc", "abc");
    emailClient.UseDefaultCredentials = true;
    emailClient.Credentials = SMTPUserInfo;
    emailClient.Send(message);

Possible Duplicate:
Sending an email to multiple addresses / recipients

I am using the below code, and it only sends one email - I have to send multiple emails.

For getting more than one email I use:

string connectionString = ConfigurationManager.ConnectionStrings["email_data"].ConnectionString;
        OleDbConnection con100 = new OleDbConnection(connectionString);
        OleDbCommand cmd100 = new OleDbCommand("select top 3 emails  from bulk_tbl", con100);
        OleDbDataAdapter da100 = new OleDbDataAdapter(cmd100);
        DataSet ds100 = new DataSet();
        da100.Fill(ds100);
        {
            for (int i = 0; i < ds100.Tables[0].Rows.Count; i++)
            //try
            {
                string all_emails = ds100.Tables[0].Rows[i][0].ToString();
                {
                    string allmail = all_emails + ";";
                    Session.Add("ad_emails",allmail);
                    Response.Write(Session["ad_emails"]);
                    send_mail();
                }
            }
        }
    }

and for sending one email I use

    string sendto = Session["ad_emails"].ToString();

    MailMessage message = new MailMessage("[email protected]", sendto, "subject", "body");
    SmtpClient emailClient = new SmtpClient("mail.smtp.com");
    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("abc", "abc");
    emailClient.UseDefaultCredentials = true;
    emailClient.Credentials = SMTPUserInfo;
    emailClient.Send(message);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-09-15 17:54:17

尝试将代码的发送部分放入循环中。以下行:

emailClient.Send(message);

例如,仅发送一封电子邮件。

Try putting the sending portion of the code in a loop. The following line:

emailClient.Send(message);

only sends one email, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文