private void QuickSendSMS(MsgQueue msg) { msg.UpdateSend(); string type = SettingManager.Get<MessageConfig>().SmsType; var smsSever = DbProvider.D<SmsServer>().FirstOrDefault(x => x.ClassName == type); if (smsSever == null) { var m = DbProvider.GetByID<MsgQueue>(msg.ID); m.IsSuccess = false; m.Result = "未设置默认短信通道"; DbProvider.SaveChanges(); return; } var sender = SMSSender.CreateInstance(new SMSAttribute { Config = smsSever.Config.Values.ToArray(), Name = smsSever.ServerName, SmsAccount = smsSever.UserName, SmsPassword = smsSever.Password, TypeName = smsSever.ClassName }); if (sender == null) { var m = DbProvider.GetByID<MsgQueue>(msg.ID); m.IsSuccess = false; m.Result = "短信通道不存在"; DbProvider.SaveChanges(); return; } try { sender.Send(msg.Dest, msg.Content); var m = DbProvider.GetByID<MsgQueue>(msg.ID); m.IsSuccess = true; DbProvider.SaveChanges(); } catch (Exception ex) { var m = DbProvider.GetByID<MsgQueue>(msg.ID); m.IsSuccess = false; m.Result = ex.Message; DbProvider.SaveChanges(); } }
private void SendMailMessage(MsgQueue msg) { var config = SettingManager.Get<EmailConfig>(); IEmailSender sender = new EmailSender(config.SmtpServer, config.SmtpPort, config.Name, config.SmtpUserName, config.SmtpPassword, config.IsSSL); sender.SendMail(msg.Dest, msg.Title, msg.Content, msg.ID, (o, e) => { var m = DbProvider.GetByID<MsgQueue>(e.UserState); if (e.Error != null) { m.IsSuccess = false; m.Result = e.Error.Message; } else { m.IsSuccess = true; } DbProvider.SaveChanges(); }); }