这是代码。我也尝试过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++;
}