首页 新闻 会员 周边 捐助

Mvc3 异步发送邮件

0
悬赏园豆:60 [待解决问题]
 1  public void Emails(string email) {
 2             try
 3             {
 4                 AsyncCallback ac = new AsyncCallback(call);
 5 
 6                 MailMessage mail = new MailMessage();
 7                 mail.From = new MailAddress("jiancixiuxian@gmail.com","aaa",Encoding.UTF8); ;
 8                 mail.To.Add(email);
 9                 mail.Subject = "aaaa";
10                mail.SubjectEncoding = Encoding.UTF8;
11                 mail.Body = "aaaa";
12                 mail.IsBodyHtml = true;
13                 mail.Priority = MailPriority.High;
14 
15                 SmtpClient sc = new SmtpClient();
16                 sc.Host = "smtp.gmail.com";
17                 sc.Port = 587;
18                 sc.Credentials = new NetworkCredential("jiancixiuxian@gmail.com", 此处密码);
19                 sc.DeliveryMethod = SmtpDeliveryMethod.Network;
20                 sc.EnableSsl = true;
21                 sc.SendCompleted += sc_SendCompleted;
22                 sc.SendAsync(mail, null);
23 
24                 
25             }
26             catch (SmtpException c)
27             {
28                 
29                 throw;
30             }
31            
32         }
33 
34         void sc_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
35         {
36           
37         }

运行就报错了

 

现在无法开始异步操作。异步操作只能在异步处理程序或模块中开始,或在页生存期中的特定事件过程中开始。如果此异常在执行 Page 时发生,请确保 Page 标记为 <%@ Page Async="true" %>。

 

求大神们解答

xiuxian的主页 xiuxian | 初学一级 | 园豆:142
提问于:2012-12-02 01:30
< >
分享
所有回答(1)
0

就是在页面上要加一个关键字<%@ Page Async="true" %>

如果你用的rozar的话,你就在后台开个线程来处理即可

az235 | 园豆:8483 (大侠五级) | 2012-12-02 09:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册