コード例 #1
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)
            });
        }