public Task SendAsync(IdentityMessage message) { // 在此处插入电子邮件服务可发送电子邮件。 EmailSender2 sender = new EmailSender2(); return(sender.SendEmailAsync(message.Destination, message.Subject, message.Body)); }
public async Task <string> SendMsgCodeAsync(string To, string regtype) { try { switch (regtype) { case "email": Random r = new Random(); int emailcode = r.Next(10000, 100000); EmailSender2 sender = new EmailSender2(); await sender.SendEmailAsync(To, "注册凭证", emailcode.ToString(), SendEmailType.注册验证码); Session["EmailCode"] = emailcode; return("信息发送成功"); case "phone": string userid = User.Identity.GetUserId(); string phonecode = UserManager.GenerateChangePhoneNumberToken(userid, To); if (UserManager.SmsService == null) { return("信息发送失败:未发现SMS短信服务"); } else { var message = new IdentityMessage { Destination = To, Body = "你的安全代码是:" + phonecode }; await UserManager.SmsService.SendAsync(message); Session["PhoneCode"] = phonecode; return("信息发送成功"); } default: return("验证信息发送失败:未能识别的注册类型:" + regtype); } } catch (Exception ex) { return("信息发送失败," + ex.Message); } }