private void SendEmail( Election election, EmailDefinition definition, RecipientIdsGenerator recipientIdsGenerator, IJobCancellationToken cancellationToken ) { if (!definition.IsEnabled) { return; } if (recipientIdsGenerator == null) { recipientIdsGenerator = DefaultGenerateRecipientIds; } string[] recipientIds = recipientIdsGenerator(election).ToArray(); int definitionId = definition.Id; cancellationToken.ThrowIfCancellationRequested(); ScheduleJobsInTransaction( recipientIds, (userId, jobClient) => jobClient.Enqueue <StudentMailerJob>( mailer => mailer.SendSingleEmail(definitionId, userId) ) ); }
public void SendSingleEmail(int emailDefinitionId, string recipientUserId) { EmailDefinition definition = _db.EmailDefinitions.Find(emailDefinitionId); TimetableUserEntry user = _timetableUserRepository.GetByUsername(recipientUserId); if (definition == null) { throw new ArgumentOutOfRangeException(nameof(emailDefinitionId), "No email definition with such id"); } if (user == null) { throw new ArgumentOutOfRangeException(nameof(user), "No timetable user entry with such id"); } MailMessage message = new MailMessage { Subject = definition.Subject, Body = definition.Body, IsBodyHtml = true, From = EmailHelpers.DefaultSender, To = { new MailAddress(user.InternalEmail, user.Fullname) }, }; _smtpClient.Send(message); }
private EmailDefinition CreateEmailDefinitionObject() { var emailDefinitionKey = $"{Guid.NewGuid()}"; var emailDefinitionName = $"{Guid.NewGuid()}"; var emailAsset = CreateAssetObject(); try { var createAssetResult = assetApiClient.CreateAsset(emailAsset); var customerKey = createAssetResult.CustomerKey; var content = new EmailDefinitionContent(customerKey); const string subscribersListKey = "All Subscribers"; var subscriptions = new EmailDefinitionSubscriptions(subscribersListKey); var emailDefinition = new EmailDefinition(emailDefinitionName, emailDefinitionKey, content: content, subscriptions: subscriptions); return(emailDefinition); } catch (ApiException e) { Console.WriteLine(e); throw; } }
protected void SendCommonEmail(int electionId, IJobCancellationToken cancellationToken, Func <Election, EmailDefinition> emailDefinitionFetcher, RecipientIdsGenerator recipientIdsGenerator = null ) { Election election = GetElection(electionId); EmailDefinition definition = emailDefinitionFetcher(election); cancellationToken.ThrowIfCancellationRequested(); SendEmail(election, definition, recipientIdsGenerator, cancellationToken); }
protected void SendCouncilEmail( int electionId, IJobCancellationToken cancellationToken, Func <CouncilElectionData, EmailDefinition> emailFetcher, RecipientIdsGenerator recipientIdsGenerator = null ) { Election election = GetElection(electionId); EmailDefinition definition = emailFetcher(GetCouncilData( election, "Requested to send council-specific email for election that isn't a council one" )); SendEmail(election, definition, recipientIdsGenerator, cancellationToken); }
public EmailDefinition BuilConfirmAccountEmail(string token, BaseUserInfo user) { var urlHelper = UrlHelperFactory.GetUrlHelper(ActionContextAccessor.ActionContext); string confirmationLink = AppWww + urlHelper.Action("ConfirmEmail", "User", new { username = user.UserName, token = token }); var builder = new BodyBuilder(); builder.TextBody = $"Witaj {user.FirstName} {user.LastName}! Kliknij w ten link aby potwierdzić twój adres email: {confirmationLink}"; EmailDefinition emailDefinition = new EmailDefinition() { To = BuildEmailAddress(user), Subject = "Potwierdzenie adresu e-mail", Body = builder.TextBody }; return(emailDefinition); }
public EmailDefinition BuildResetPasswordEmail(string token, BaseUserInfo user) { var urlHelper = UrlHelperFactory.GetUrlHelper(ActionContextAccessor.ActionContext); string resetPasswordLink = AppWww + urlHelper.Action("SetNewPassword", "User", new { username = user.UserName, token = token }); var builder = new BodyBuilder(); builder.TextBody = $"Witaj {user.FirstName} {user.LastName}! Kliknij w ten link aby zresetować hasło: {resetPasswordLink}"; EmailDefinition emailDefinition = new EmailDefinition() { To = BuildEmailAddress(user), Subject = "Reset hasła", Body = builder.TextBody }; return(emailDefinition); }