0

我有一个函数,它获取地址列表并使用 google smtp 向列表中的每个联系人发送相同的电子邮件。但我担心我的代码效率不高,因为它发送了几封单独的邮件。如何将更多联系人添加到同一客户并一次发送所有联系人?

这是我的功能:

protected void btn_click(object sender, EventArgs e, List<string> address_l, List<string> names)
    {
        for (int i = 0; i < address_l.Count; i++)
        {
            var fromAddress = new MailAddress("dvir.rez@gmail.com", "Dvir");
            var toAddress = new MailAddress(address_l[i], names[i]);

            const string fromPassword = "2.4.862.4.86";
            const string subject = "test";
            string body = "Test body";

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
            {
                smtp.Send(message);
            }
        }

    }
4

1 回答 1

4

使用密件抄送添加“密件抄送”收件人 - 他们将收到邮件的副本,而不会看到其他密件抄送的电子邮件地址。

for (int i = 0; i < address_l.Count; i++)
{
   message.Bcc.Add(new MailAddress(address_l[i], names[i]));
}
于 2013-05-29T14:38:07.767 回答