public async Task <ResultDto> CreateEmailHistoryInfo(createEmailHistoryInfoDto createEmailHistoryInfoDto, bool?isSendEmail = true)
        {
            // 检测邮箱账号为否为QQ邮箱,并且是否正确
            string expression = AppConfigurtaionService.Configuration["EmailServicesStrings:EmailExpression"];

            if (!Regex.IsMatch(createEmailHistoryInfoDto.RecipientId, expression, RegexOptions.Compiled))
            {
                // 请输入正确的QQ邮箱账号
                throw new Exception("Please enter the correct QQ email account.");
            }
            EmailHistoryInfo emailHistory = new EmailHistoryInfo()
            {
                RecipientId = createEmailHistoryInfoDto.RecipientId,
                EmailBody   = createEmailHistoryInfoDto.EmailBody
            };

            // 发送QQ邮件
            if (isSendEmail.Value)
            {
                emailHistory.EmailBody = _emailServices.SendRandomCode(emailHistory.RecipientId);
            }
            await _context.EmailHistoryInfo.AddAsync(emailHistory);

            return(new ResultDto()
            {
                Success = await _context.SaveChangesAsync() > 0 ? true : false
            });
        }
示例#2
0
        public async Task <ResultDto> CreateEmailHistoryInfo(createEmailHistoryInfoDto createEmailHistoryInfoDto)
        {
            // 检测邮箱账号为否为QQ邮箱,并且是否正确
            string expression = AppConfigurtaionService.Configuration["EmailServicesStrings:EmailExpression"]; // 拿到配置文件中的正则表达式

            if (!Regex.IsMatch(createEmailHistoryInfoDto.RecipientId, expression, RegexOptions.Compiled))
            {
                // 请输入正确的QQ邮箱账号
                throw new Exception("Please enter the correct QQ email account.");
            }
            var emailHistory = ModelBindingService.CopyModel <HW_EmailHistoryInfo, createEmailHistoryInfoDto>(createEmailHistoryInfoDto);

            // 发送QQ邮件
            if (createEmailHistoryInfoDto.IsSendEmail)
            {
                emailHistory.EmailBody = _emailServices.SendRandomCodeQQEmail(emailHistory.RecipientId).RecipientBody;
            }
            return(new ResultDto()
            {
                Success = await _context.Add(emailHistory)
            });
        }