예제 #1
0
        public async Task SendNewCommentEmail(CommentVM comment, int teamId)
        {
            var subscribers = await userRepository.GetSubscribers(teamId, NotificationTypeCode.NewComment);

            var emailTemplate = emailTemplateRepository.GetEmailTemplate("NewComment");

            if (emailTemplate != null)
            {
                string emailSubject = emailTemplate.Subject;
                string emailBody    = emailTemplate.EmailBody;
                Email  email        = new Email();


                string issueUrl  = UrlBuilderHelper.SiteBaseUrl + "issues/" + comment.IssueId;
                var    issueLink = "<a href='" + issueUrl + "'>" + "# " + comment.IssueId + " " + comment.IssueId + "</a>";
                emailBody     = emailBody.Replace("@author", comment.Author.Name);
                emailBody     = emailBody.Replace("@link", issueLink);
                emailBody     = emailBody.Replace("@comment", comment.CommentBody);
                emailBody     = emailBody.Replace("@issueId", comment.IssueId.ToString());
                email.Body    = emailBody;
                emailSubject  = emailSubject.Replace("@issueId", comment.IssueId.ToString());
                email.Subject = emailSubject;

                foreach (var subscriber in subscribers)
                {
                    email.ToAddress.Add(subscriber.EmailAddress);
                }

                email.Send();
            }
        }
        public async Task SendEmail(string templateName, string toAddress, dynamic tokens, string replyToAddress)
        {
            //TODO: Pass in INotificationClient to ctor, create transient with ApiKey


            //var client = new NotificationClient(_configuration.GovNotifyApiKey);


            var emailTemplate = await _emailTemplateRepository.GetEmailTemplate(templateName);

            //TODO: Make sure the id is the one we expectGet template from db
            //var templateId = "192e704d-a5db-4f77-9b20-4eb9cdff5501";
            if (emailTemplate != null)
            {
                var personalisationTokens = new Dictionary <string, dynamic>();
                foreach (var property in tokens.GetType().GetProperties())
                {
                    personalisationTokens[property.Name] = property.GetValue(tokens);
                }

                //TODO: Set up replytoid - see on https://docs.notifications.service.gov.uk/net.html#send-an-email-arguments-personalisation-optional
                _notificationClient.SendEmail(
                    emailAddress: toAddress,
                    templateId: emailTemplate.TemplateId,
                    personalisation: personalisationTokens);
            }
        }
예제 #3
0
        public void Add(EnquiryForm01Dto customer)
        {
            using (var transaction = new TransactionScope())
            {
                customer.Email = customer.Email.ToLower().Trim();
                if (CheckEmailExist(customer.Email, customer.PromotionGroupType))
                {
                    _customerRepository.Insert(customer.MapTo <Customer>());
                    transaction.Complete();
                }

                // send out email
                var emailTemplate =
                    _emailTemplateRepository.GetEmailTemplate(new Guid("BFFF3CBF-D9F5-4699-A593-16DDD016E158"));

                _emailSender.SendEmail(
                    emailTemplate.Subject,
                    emailTemplate.BodyTemplate,
                    emailTemplate.IsBodyHtml,
                    MailPriority.Normal,
                    Encoding.UTF8,
                    emailTemplate.From,
                    customer.Email,
                    emailTemplate.ReplyTo,
                    emailTemplate.Bcc,
                    GetTokenValues(customer)
                    );
            }
        }
예제 #4
0
        public void SendResetPasswordEmail(UserAccountDto userAccount, string activationLink)
        {
            var emailTemplate = repository.GetEmailTemplate("ResetPassword");

            if (emailTemplate != null)
            {
                string emailSubject = emailTemplate.Subject;
                string emailBody    = emailTemplate.EmailBody;
                Email  email        = new Email();
                email.ToAddress.Add(userAccount.EmailAddress);

                string joinLink = $"{UrlBuilderHelper.SiteBaseUrl}Account/resetpassword/{activationLink}";
                emailBody     = emailBody.Replace("@resetLink", joinLink);
                email.Body    = emailBody;
                email.Subject = emailSubject;
                email.Send();
            }
        }
예제 #5
0
        public async Task SendEmail(string templateName, string toAddress, dynamic tokens, string replyToAddress)
        {
            var emailTemplate = await _emailTemplateRepository.GetEmailTemplate(templateName);

            if (emailTemplate != null)
            {
                var recipients = new List <string>();

                if (!string.IsNullOrWhiteSpace(toAddress))
                {
                    recipients.Add(toAddress.Trim());
                }

                if (!string.IsNullOrWhiteSpace(emailTemplate.Recipients))
                {
                    recipients.AddRange(emailTemplate.Recipients.Split(';').Select(x => x.Trim()));
                }

                var personalisationTokens = new Dictionary <string, string>();

                foreach (var property in tokens.GetType().GetProperties())
                {
                    personalisationTokens[property.Name] = property.GetValue(tokens);
                }

                if (string.IsNullOrWhiteSpace(replyToAddress))
                {
                    replyToAddress = REPLY_TO_ADDRESS;
                }

                foreach (var recipient in recipients)
                {
                    _logger.LogInformation($"Sending {templateName} email to {recipient}");
                    await SendEmailViaNotificationsApi(recipient, emailTemplate.TemplateId, personalisationTokens, replyToAddress);
                }
            }
        }
예제 #6
0
        public EmailTemplateDto GetEmailTemplate(string templateID)
        {
            var emailTemplate = _emailTemplateRepository.GetEmailTemplate(templateID);

            return(_mapper.Map <EmailTemplateDto>(emailTemplate));
        }
 public Task <List <EmailTemplate> > GetEmailTemplate(EmailTemplate obj)
 {
     return(_EmailTemplateRepository.GetEmailTemplate(obj));
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="templateName"></param>
 /// <returns></returns>
 private IEmailTemplate GetEmailTemplateById(string templateName)
 {
     return(_repository.GetEmailTemplate(templateName));
 }
예제 #9
0
 public async Task <EmailTemplate> Handle(GetEmailTemplateRequest request, CancellationToken cancellationToken)
 {
     return(await _emailTemplateRepository.GetEmailTemplate(request.TemplateName));
 }