ASP.NET Controller: An asynchronous module or handler completed while an asynchronous operation was still pending

后端 未结 8 1158
一个人的身影
一个人的身影 2020-11-28 09:36

I have a very simple ASP.NET MVC 4 controller:

public class HomeController : Controller
{
    private const string MY_URL = \"http://smthing\";
    private r         


        
8条回答
  •  北海茫月
    2020-11-28 10:30

    Email notification Example With Attachment ..

    public async Task SendNotification(string SendTo,string[] cc,string subject,string body,string path)
        {             
            SmtpClient client = new SmtpClient();
            MailMessage message = new MailMessage();
            message.To.Add(new MailAddress(SendTo));
            foreach (string ccmail in cc)
                {
                    message.CC.Add(new MailAddress(ccmail));
                }
            message.Subject = subject;
            message.Body =body;
            message.Attachments.Add(new Attachment(path));
            //message.Attachments.Add(a);
            try {
                 message.Priority = MailPriority.High;
                message.IsBodyHtml = true;
                await Task.Yield();
                client.Send(message);
            }
            catch(Exception ex)
            {
                ex.ToString();
            }
     }
    

提交回复
热议问题