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