public async Task SendEmailNotification(Jobs.Model.Job job)
        {
            try
            {
                var template = await _emailTemplateManager.GetTemplate(job.JobId, job.Status, job.JobType, job.DateTimeSubmittedUtc);

                if (!string.IsNullOrEmpty(template))
                {
                    var personalisation = new Dictionary <string, dynamic>();

                    var submittedAt = _dateTimeProvider.ConvertUtcToUk(job.DateTimeSubmittedUtc);
                    personalisation.Add("JobId", job.JobId);
                    personalisation.Add("Name", job.SubmittedBy);
                    personalisation.Add("DateTimeSubmitted", string.Concat(submittedAt.ToString("hh:mm tt"), " on ", submittedAt.ToString("dddd dd MMMM yyyy")));

                    await _emailNotifier.SendEmail(job.NotifyEmail, template, personalisation);

                    _logger.LogInfo($"Sent email for jobId : {job.JobId}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Sending email failed for job {job.JobId}", ex, jobIdOverride: job.JobId);
            }
        }
        public void Consume(EmailCommandMessage message)
        {
            var notificationSentEvent = _emailNotifier.SendEmail(
                message.SenderEmail,
                message.SenderName,
                message.RecipientEmail,
                message.RecipientName,
                message.Subject,
                message.Body);

            _eventBus.Publish(notificationSentEvent);
        }
        private async Task <int> SendEmails(CancellationToken cancellationToken)
        {
            const string dateFormatString = "h tt d MMMM";
            int          emailsSentCount  = 0;

            var collection = await _collectionReferenceData.GetFundingClaimsCollectionAsync(cancellationToken);

            if (collection == null)
            {
                _logger.LogDebug("Collection closed, no emails to send");
                return(0);
            }


            var emailTemplate = await _emailTemplateService.GetEmailTemplateAsync(cancellationToken, collection.CollectionId);

            if (emailTemplate == null)
            {
                _logger.LogError("No valid Active Email Template for Collection");
                return(0);
            }

            var emails = (await _fundingClaimsEmailService.GetUnsubmittedClaimEmailAddressesAsync(cancellationToken, collection.CollectionName, collection.CollectionYear, collection.SubmissionOpenDateUtc)).ToList();

            if (!emails.Any())
            {
                _logger.LogDebug("No emails to send, as there are no providers in draft state who have not submitted");
                return(0);
            }

            foreach (var email in emails)
            {
                var parameters = new Dictionary <string, dynamic>
                {
                    { "SubmissionCloseDate", collection.SubmissionCloseDateUtc.ToString(dateFormatString) },
                    { "SignatureCloseDate", collection.SignatureCloseDateUtc.GetValueOrDefault().ToString(dateFormatString) },
                };

                try
                {
                    await _emailNotifier.SendEmail(email, emailTemplate, parameters);

                    emailsSentCount++;
                }
                catch (Notify.Exceptions.NotifyClientException e)
                {
                    _logger.LogError($"Error sending email to email address: {email}", e);
                }
            }

            return(emailsSentCount);
        }
Exemple #4
0
        public void SendInvitation(InvitationModel model, long userId)
        {
            var checkEmail = _accessTokenRepository.GetWebUserByEmail(model.Email);

            if (checkEmail != null)
            {
                throw new Exception("L'identificador de correu electrònic ja existeix.");
            }

            var invitationId = InsertWebUserInvitation(model, userId);
            var webUrl       = ConfigurationManager.AppSettings["WebUrl"];
            var fields       = new StringDictionary
            {
                { "signUpUrl", string.Format("{0}{1}{2}", webUrl, "/Employee/Invitation/", invitationId) }
            };
            var htmlBody = _fm.ReadFileContents(GetMailerTemplatePath("html", "CreateEmployeePage")).ReplaceMatch(fields);

            _emailNotifier.SendEmail(model.Email, htmlBody, "Invitation");
        }
Exemple #5
0
        public async Task SendEmailNotification(long jobId)
        {
            try
            {
                var job = await GetJobById(jobId);

                var template = await GetTemplate(jobId, job.Status, job.JobType, job.DateTimeSubmittedUtc);

                if (!string.IsNullOrEmpty(template))
                {
                    var personalisation = new Dictionary <string, dynamic>();

                    var submittedAt = _dateTimeProvider.ConvertUtcToUk(job.DateTimeSubmittedUtc);

                    personalisation.Add("JobId", job.JobId);
                    personalisation.Add("Name", job.SubmittedBy);
                    personalisation.Add(
                        "DateTimeSubmitted",
                        string.Concat(submittedAt.ToString("hh:mm tt"), " on ", submittedAt.ToString("dddd dd MMMM yyyy")));

                    var nextReturnPeriod = GetNextReturnPeriod(job.CollectionName);
                    personalisation.Add("FileName", job.FileName);
                    personalisation.Add("CollectionName", job.CollectionName);
                    personalisation.Add(
                        "PeriodName",
                        $"R{job.PeriodNumber.ToString("00", NumberFormatInfo.InvariantInfo)}");
                    personalisation.Add("Ukprn", job.Ukprn);
                    if (nextReturnPeriod != null)
                    {
                        personalisation.Add("NextReturnOpenDate", nextReturnPeriod.StartDateTimeUtc.ToString("dd MMMM yyyy"));
                    }

                    await _emailNotifier.SendEmail(job.NotifyEmail, template, personalisation);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Sending email failed for job {jobId}", ex, jobIdOverride: jobId);
            }
        }
Exemple #6
0
        public object ValidateAndCreateUser(RegisterModel model)
        {
            var  message  = string.Empty;
            User authUser = null;

            //_userRegistrationValidators.Validate(model);

            if (!string.IsNullOrEmpty(model.AuthId))
            {
                var oAuthIdExist = false;
                var emailIdExist = false;
                _accessTokenRepository.CheckOAuthUserExistsAndCheckEmailExists(model.AuthId, model.UserName, out oAuthIdExist, out emailIdExist);
                if (emailIdExist)
                {
                    var user = _accessTokenRepository.GetUserByEmail(model.UserName);
                    if (user != null)
                    {
                        model.Id = user.Id;
                        var loginMap = LoginWithFacebookMapperForOAuthUserEmail(model);
                        _accessTokenRepository.OAuthEmailUserUpdate(loginMap);
                        authUser = user;
                        var emailToken = TokenMapper(authUser as User, _accessTokenRepository.CreateToken(authUser));
                        return(emailToken);
                    }
                }
                else
                {
                    var user = UserAudienceCredentialsMapper(model);
                    user.IsVerified = true;
                    user.UserCode   = Convert.ToString(Guid.NewGuid());
                    SaveUserCode(user.UserCode);
                    var userId = _accessTokenRepository.CreateNewUser(user);
                    user.Id  = userId;
                    authUser = user;
                    message  = "Användare tillagd.";
                    var emailToken = TokenMapper(authUser as User, _accessTokenRepository.CreateToken(authUser), message);
                    return(emailToken);
                }
            }
            else
            {
                _userRegistrationValidators.Validate(model);
                var user = UserAudienceCredentialsMapper(model);
                user.UserCode = Convert.ToString(Guid.NewGuid());
                SaveUserCode(user.UserCode);
                var userId = _accessTokenRepository.CreateNewUser(user);
                user.Id  = userId;
                authUser = user;
                message  = "Användare tillagd.";
            }
            var webUrl = ConfigurationManager.AppSettings["WebUrl"];

            var fields = new StringDictionary
            {
                { "signUpUrl", string.Format("{0}{1}{2}{3}", Convert.ToString(webUrl), "/Email/ConfirmEmail?id=", _cryptoGraphy.EncryptString(Convert.ToString(authUser.Id)), "&email=" + _cryptoGraphy.EncryptString(authUser.Email)) }
            };

            message = "Vi har sänt dig ett verifikationsemail, vänligen verifiera din emailadress.";

            var htmlBody = _fm.ReadFileContents(GetMailerTemplatePath("html", "CreateUser")).ReplaceMatch(fields);

            _emailNotifier.SendEmail(authUser.Email, htmlBody, "Verify Link");
            var registerResponse = new RegisterResponse
            {
                UserId  = authUser.Id,
                Message = message
            };

            //var token = TokenMapper(authUser as User, _accessTokenRepository.CreateToken(authUser));
            //token.Message = message;
            return(registerResponse);
        }