コード例 #1
0
ファイル: BaseBAL.cs プロジェクト: laythm/LMYFrameWorkMVC
        protected void SendEmail(string subject, string body, List <MailAddress> to, List <MailAddress> cc = null)
        {
            EmailInfo emailInfo = new EmailInfo();

            emailInfo.To      = to;
            emailInfo.CC      = cc;
            emailInfo.Subject = subject;
            emailInfo.Body    = body;

            //set smtp info
            //emailInfo.SMTPInfo.From;

            Helpers.EmailHelper emailHelper = new Helpers.EmailHelper();
            Action action = (async() =>
            {
                try
                {
                    //IQueryable<AspNetUser> AspNetUsers = dbContext.AspNetUsers.Where(x => to.Any(y => y.Email == x.Email));
                    await emailHelper.SendEmail(emailInfo);
                }
                catch (Exception ex)
                {
                    this.HandleError(null, LookUps.ErrorType.Exception, ex);
                }
            });

            this.AddAfterExecutionAction(action);
        }
コード例 #2
0
        public IW2SUserDto FindPwd(string email, string loginName)
        {
            if (string.IsNullOrEmpty(email))
            {
                return new IW2SUserDto {
                           Error = "邮箱不能为空"
                }
            }
            ;
            bool dd = System.Text.RegularExpressions.Regex.IsMatch(email, @"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");

            if (dd == false)
            {
                return new IW2SUserDto {
                           Error = "邮箱格式不正确!"
                }
            }
            ;
            // MongoDBHelper<FreeUser> dbhelper = new MongoDBHelper<FreeUser>();
            var builder = Builders <IW2SUser> .Filter;
            var filter  = builder.Eq(x => x.UsrEmail, email);

            filter &= builder.Eq(x => x.LoginName, loginName);

            var _usr = MongoDBHelper.Instance.Get_IW2SUser().Find(filter).FirstOrDefault();

            if (_usr != null)
            {
                int gg = new Random().Next(100000, 999999);

                Guid md5 = EncryptHelper.GetEncryPwd(gg.ToString());
                var  updateWebsiteCount = new UpdateDocument {
                    { "$set", new QueryDocument {
                          { "LoginPwd", md5 }
                      } }
                };
                // dbhelper.Update("FreeUser", new QueryDocument { { "_id", _usr._id } }, updateWebsiteCount);
                MongoDBHelper.Instance.Get_IW2SUser().UpdateOne(new QueryDocument {
                    { "_id", _usr._id }
                }, updateWebsiteCount);
                Helpers.EmailHelper ems = new Helpers.EmailHelper();
                string CC      = "";
                string Bcc     = "";
                string Subject = "密码找回";                                                                //主题
                System.Net.Mail.LinkedResource[] EmbeddedResources = null;                              //嵌入的外部资源
                System.Net.Mail.Attachment[]     Attachments       = null;                              //附件
                string From     = AISSystem.AppSettingHelper.GetAppSetting("ems_usr_acc");              //发件人
                string UserName = AISSystem.AppSettingHelper.GetAppSetting("ems_usr_name");             //发件人用户名
                string Password = AISSystem.AppSettingHelper.GetAppSetting("ems_usr_pwd");              //密码
                string Server   = AISSystem.AppSettingHelper.GetAppSetting("ems_smtp");                 //发件邮箱服务器
                int    Port     = int.Parse(AISSystem.AppSettingHelper.GetAppSetting("ems_smtp_port")); //邮箱端口
                bool   UseSSL   = false;                                                                //是否使用
                ems.SendMail(email, From, Bcc, Subject, "<div><p>" + _usr.LoginName + ",您好!</p><p>您的初始密码是:" + gg + "</p><p>登陆系统后,请自行修改密码!</p></div>",
                             EmbeddedResources, Attachments, UserName, UserName, "xiaofeng123", "smtp.163.com", 25, UseSSL);
                return(new IW2SUserDto {
                    Error = "密码已经发送到您的邮箱,请及时查看!"
                });
            }
            else
            {
                return(new IW2SUserDto {
                    Error = "您填写的邮箱与注册时填写不一致,请重试!"
                });
            }
        }