public async Task SendAsync(string from, List <string> to, string subject, string body, bool isHtmlBody, List <string> fileAttachments, int descriptor) { var email = new EmailProxy { From = from, Body = body, IsHtml = isHtmlBody, Subject = subject, DescriptorId = descriptor, Recipients = new List <EmailRecipientProxy>(), Attachments = new List <AttachmentProxy>() }; foreach (var address in to.Where(address => !string.IsNullOrEmpty(address))) { email.Recipients.Add(new EmailRecipientProxy { EmailAddress = address }); } foreach (var attachment in fileAttachments.Where(attachment => !string.IsNullOrEmpty(attachment))) { email.Attachments.Add(new AttachmentProxy { FilePath = attachment }); } await SendAsync(email); }
private async Task SendAsync(EmailProxy email) { if (string.IsNullOrEmpty(email.From)) { throw new EmailFormatException("From field cannot be blank"); } if (email.Recipients.Count <= 0) { throw new EmailFormatException("A minimum of one recipient is required"); } if (string.IsNullOrEmpty(email.Body)) { throw new EmailFormatException("The body of the mail cannot be blank"); } foreach (var attachment in email.Attachments) { if (!File.Exists(attachment.FilePath)) { throw new EmailFormatException("The attached file at " + attachment.FilePath + " does not exist"); } } _repository.Add((OutboundEmail)email); await _repository.CommitChangesAsync(); }
public void TestSendEmail() { try { var batch = EmailProxy.SendEmail(0, "subject", "", "*****@*****.**", "hahahahahha"); } catch (Exception ex) { throw ex; } }
public HttpResponseMessage SendMail(EmailProxy email) { try { this._emailSender.Send(new Service.Model.Email { SenderName = email.Sender, SenderEmail = email.Email, Message = email.Message }); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (System.Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }
public BindResult Bind(Dictionary <string, string> openIds, string batch, string userName, string password, string captcha) { var result = new BindResult { NeedCaptcha = false }; var callback = ProviderGateway.CallbackContentProvider.GetByBatchId(batch); var appAccountPublic = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPublic); if (!openIds.ContainsKey(appAccountPublic.AppId)) { result.Result = 2; result.Message = "用户公有OpenId无效"; return(result); } AppAccountInfo appAccountPrivate = null; if (callback.TenantId != 0) { appAccountPrivate = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPrivate); if (!openIds.ContainsKey(appAccountPrivate.AppId)) { result.Result = 2; result.Message = "用户私有OpenId无效"; return(result); } } var openIdPublic = openIds[appAccountPublic.AppId]; var currentAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, openIdPublic); if (currentAppUserAccount != null && currentAppUserAccount.State == AppUserAccountState.Activated) { result.Result = 8; result.Message = "您已经绑定过了,无需重复绑定"; return(result); } //验证发送时间 if (RedisHelper.IsExist(RedisConstName.SendCheck + userName)) { result.Result = 6; result.Message = "绑定过于频繁"; return(result); } // 校验邮箱是否存在 var userId = Proxy.BeisenUserProxy.GetSecurityByUserName(userName); if (userId <= 0) { result.Result = 5; result.Message = "未找到对应账户"; return(result); } var tenantId = Proxy.BeisenUserProxy.GetTenantId(userId); var oldAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByUserId(tenantId, userId, appAccountPublic.AppId); if (oldAppUserAccount != null && oldAppUserAccount.State == AppUserAccountState.Activated) { result.Result = 7; result.Message = "帐号已绑定"; return(result); } var newAppUserAccountMaster = new AppUserAccountInfo { AppId = appAccountPublic.AppId, OpenId = openIdPublic, TenantId = tenantId, UserId = userId, BeisenAccount = userName, Type = _type, State = AppUserAccountState.Inactive, MasterAccountId = 0 }; var masterAccountId = ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppUserAccountMaster); //增加私有关联关系 if ((appAccountPublic.Type == 11 || appAccountPublic.Type == 12) && callback.TenantId != 0 && masterAccountId != 0) { var newAppAccountUser = new AppUserAccountInfo { AppId = appAccountPrivate.AppId, OpenId = openIds[appAccountPrivate.AppId], TenantId = tenantId, UserId = userId, BeisenAccount = userName, Type = _type, State = AppUserAccountState.Inactive, MasterAccountId = masterAccountId }; ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppAccountUser); } // 记录发邮件记录 var bindBatch = new BindBatchInfo { TenantId = tenantId, AppUserAccountId = masterAccountId, BeisenAccount = userName, Type = _type, State = BindBatchState.UnUse }; var bindBatchId = ProviderGateway.BindBatchProvider.Add(tenantId, bindBatch); // 发送激活邮件 string activateCode = CryptographyHelper.AESEncrypt(tenantId + "_" + bindBatchId); string emailBody = GetEmailBody(userName, AppConnectHostConfig.Cache[0] + HostConst.UserActivate + "?code=" + activateCode); var emailBatch = EmailProxy.SendEmail(0, "iTalent登录邮件验证", "", userName, emailBody); RedisHelper.SetRedis(RedisConstName.SendCheck + userName, DateTime.Now.Ticks.ToString(), 180); ProviderGateway.BindBatchProvider.UpdateBatchId(tenantId, bindBatchId, emailBatch); return(result); }