带有批量电子邮件的SmtpClient SendMailAsync成功发送了大约1200个,其余电子邮件失败。有指针吗?

时间:2019-05-22 17:25:23

标签: c# smtpclient

这是代码。我也尝试过SendAsync,但遇到了同样的问题。我需要向订阅者广播电子邮件。

var emails = Enumerable.Repeat("<my email address>", 1300);
        string mMailServer = "<smtp server>";

        int counter = 0;
        foreach (var item in emails)
        {
            SmtpClient client = new SmtpClient(mMailServer);
            MailMessage mm = new MailMessage("<from address>", item, "bulk test from blast", "test")
            {
                IsBodyHtml = true
            };

            var t = client.SendMailAsync(mm);
            t.ContinueWith(async (inp) =>
            {

                if (inp.IsCompletedSuccessfully)
                {
                }
                if (inp.IsFaulted)
                {
                    var ex = $"{ inp.Exception.Message} Inner Exception: { inp.Exception.InnerException?.Message }";
                    await Util.WriteToFileAsync(@"d:\errorMessages\", counter.ToString(), inp.Exception.Message);
                }
            });
            counter++;
        }

0 个答案:

没有答案