예제 #1
0
        public async IAsyncEnumerable <MailMergeMessage> GetMailMergeMessages(ITenantContext tenantContext, ITemplateRenderer renderer, IMailMergeService mailMergeService, IStringLocalizer <EmailResource> localizer, [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            if (Parameters.Email is null || Parameters.NewEmail is null || Parameters.CallbackUrl is null ||
                Parameters.DeadlineUtc is null)
            {
                throw new ArgumentNullException(nameof(Parameters), "One or more required parameters are null");
            }

            {
                using var cs = new CultureSwitcher(Parameters.CultureInfo, Parameters.CultureInfo);

                // First email goes to the new email address

                var model = new ChangeUserAccountModel()
                {
                    Email       = Parameters.NewEmail,
                    CallbackUrl = Parameters.CallbackUrl,
                    Deadline    = Parameters.DeadlineUtc
                };

                var mailMergeMessage = mailMergeService.CreateStandardMessage();
                mailMergeMessage.EnableFormatter = false;
                mailMergeMessage.Subject         = localizer["Please confirm your new primary email"].Value;

                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, tenantContext.SiteContext.Email.GeneralFrom.DisplayName, tenantContext.SiteContext.Email.GeneralFrom.Address));
                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, Parameters.NewEmail));

                mailMergeMessage.PlainText = await renderer.RenderAsync(TemplateName.ConfirmNewPrimaryEmailTxt, model,
                                                                        Parameters.CultureInfo.TwoLetterISOLanguageName);

                mailMergeMessage.HtmlText = await renderer.RenderAsync(TemplateName.ConfirmNewPrimaryEmailHtml, model,
                                                                       Parameters.CultureInfo.TwoLetterISOLanguageName);

                yield return(mailMergeMessage);

                // Second email goes to the current email address

                model = new ChangeUserAccountModel()
                {
                    Email       = Parameters.NewEmail,
                    CallbackUrl = string.Empty, // not used in the template
                    Deadline    = null          // not used in the template
                };

                mailMergeMessage = mailMergeService.CreateStandardMessage();
                mailMergeMessage.EnableFormatter = false;
                mailMergeMessage.Subject         = localizer["Your primary email is about to be changed"].Value;

                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, tenantContext.SiteContext.Email.GeneralFrom.DisplayName, tenantContext.SiteContext.Email.GeneralFrom.Address));
                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, Parameters.Email));

                mailMergeMessage.PlainText = await renderer.RenderAsync(TemplateName.NotifyCurrentPrimaryEmailTxt, model,
                                                                        Parameters.CultureInfo.TwoLetterISOLanguageName);

                mailMergeMessage.HtmlText = await renderer.RenderAsync(TemplateName.NotifyCurrentPrimaryEmailHtml, model,
                                                                       Parameters.CultureInfo.TwoLetterISOLanguageName);

                yield return(mailMergeMessage);
            }
        }
예제 #2
0
        public async IAsyncEnumerable <MailMergeMessage> GetMailMergeMessages(ITenantContext tenantContext, ITemplateRenderer renderer, IMailMergeService mailMergeService, IStringLocalizer <EmailResource> localizer, [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            if (Parameters.Email is null || Parameters.Subject is null || Parameters.CallbackUrl is null ||
                Parameters.TemplateNameTxt is null || Parameters.TemplateNameHtml is null ||
                Parameters.DeadlineUtc is null)
            {
                throw new ArgumentNullException(nameof(Parameters), "One or more required parameters are null");
            }

            var model = new ChangeUserAccountModel()
            {
                Email       = Parameters.Email,
                CallbackUrl = Parameters.CallbackUrl,
                Deadline    = Parameters.DeadlineUtc
            };

            {
                using var cs = new CultureSwitcher(Parameters.CultureInfo, Parameters.CultureInfo);

                var mailMergeMessage = mailMergeService.CreateStandardMessage();
                mailMergeMessage.EnableFormatter = false;
                mailMergeMessage.Subject         = Parameters.Subject; // already localized

                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, tenantContext.SiteContext.Email.GeneralFrom.DisplayName, tenantContext.SiteContext.Email.GeneralFrom.Address));
                mailMergeMessage.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, Parameters.Email));

                mailMergeMessage.PlainText = await renderer.RenderAsync(Parameters.TemplateNameTxt, model,
                                                                        Parameters.CultureInfo.TwoLetterISOLanguageName);

                mailMergeMessage.HtmlText = await renderer.RenderAsync(Parameters.TemplateNameHtml, model,
                                                                       Parameters.CultureInfo.TwoLetterISOLanguageName);

                yield return(mailMergeMessage);
            }
        }
예제 #3
0
        public void ConfirmNewPrimaryEmail_Test(string cultureName)
        {
            var m = new ChangeUserAccountModel
            {
                Email    = "*****@*****.**", CallbackUrl = "https://axuno.net/callback",
                Deadline = new DateTime(2021, 01, 01, 12, 00, 00)
            };

            string text = string.Empty, html = string.Empty;

            Assert.Multiple(() =>
            {
                Assert.DoesNotThrowAsync(async() =>
                {
                    text = await _renderer.RenderAsync(TemplateName.ConfirmNewPrimaryEmailTxt, m, cultureName);
                    Console.WriteLine($"*** {TemplateName.ConfirmNewPrimaryEmailTxt} ***");
                    Console.WriteLine(text);
                    html = await _renderer.RenderAsync(TemplateName.ConfirmNewPrimaryEmailHtml, m, cultureName);
                    Console.WriteLine($"*** {TemplateName.ConfirmNewPrimaryEmailHtml} ***");
                    Console.WriteLine(html);
                });

                Assert.That(text.Contains(L("Change your primary email address", cultureName)));
                Assert.That(html.Contains(L("Change your primary email address", cultureName)));
            });
        }