我如何发送延迟10秒异步并行的电子邮件

时间:2015-12-20 00:35:30

标签: c# asp.net-mvc-5

  

我希望每隔10秒发送4封电子邮件异步并行,此代码

     

仅发送第一封电子邮件,我希望在发送4封电子邮件之后

     

将等待10秒,然后再继续发送4封电子邮件

 public static void  SendEmail(string mail)
        {
            BackgroundTaskRunner.FireAndForgetTask(async () =>
            {
            var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                 Credentials = new NetworkCredential("mail", "password"),
                    Timeout = 20000
                };
                using (var message = new MailMessage("frommail", mail)
            {
                Subject = "",
                Body = "",
                IsBodyHtml = false           
            })
            {               
                    await smtp.SendMailAsync(message);          
            }
            });
        }

HostingEnvironment.QueueBackgroundWorkItem(async cancellationToken =>                         {                             尝试                             {                                 等待行动();                             }                             catch(例外e)                             {                                 // TODO:处理异常                             }                         });                     }                 }

{{1}}
{{1}}

0 个答案:

没有答案