示例#1
0
        public void Should_Generate_NewPost_EmailContent(int retries)
        {
            var mailTemplate = new MailTemplate();

            var newWallPostEmailTemplateViewModel = new NewWallPostEmailTemplateViewModel(
                "WallTitle",
                "http://picture.example.com",
                "Iam Creator",
                "http://post.example.com/1",
                "body",
                "http://settings.example.com/1",
                "Read it");

            var kudosSentEmailTemplateViewModel = new KudosSentEmailTemplateViewModel(
                "http://settings.example.com/1",
                "Iam Creator",
                10,
                "New kudos for you!",
                "http://profile.example.com/1");

            for (var i = 0; i < retries; i++)
            {
                TestContext.Progress.WriteLine($"Generating {i + 1}/{retries}");

                mailTemplate.Generate(newWallPostEmailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);
                mailTemplate.Generate(kudosSentEmailTemplateViewModel, EmailTemplateCacheKeys.KudosSent);
            }
        }
示例#2
0
        public void NotifyAboutNewPost(NewlyCreatedPostDTO post)
        {
            var postCreator = _userService.GetApplicationUser(post.User.UserId);

            var organization = _organizationService.GetOrganizationById(postCreator.OrganizationId);
            var wall         = _wallsDbSet.Single(w => w.Id == post.WallId);

            var destinationEmails           = _userService.GetWallUsersEmails(postCreator.Email, wall);
            var postLink                    = GetPostLink(post.WallType, post.WallId, organization.ShortName, post.Id);
            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(
                GetWallTitle(wall),
                authorPictureUrl,
                postCreator.FullName,
                postLink,
                body,
                userNotificationSettingsUrl,
                GetActionButtonTitle(wall));
            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);

            _mailingService.SendEmail(emailData);
        }
        private async Task SendWallSubscriberEmailsAsync(NewlyCreatedPostDto post,
                                                         IEnumerable <string> destinationEmails,
                                                         ApplicationUser postCreator,
                                                         Organization organization,
                                                         MultiwallWall wall)
        {
            var postLink = await GetPostLinkAsync(post.WallType, post.WallId, organization.ShortName, post.Id);

            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(GetWallTitle(wall),
                                                                               authorPictureUrl,
                                                                               postCreator.FullName,
                                                                               postLink,
                                                                               body,
                                                                               userNotificationSettingsUrl,
                                                                               GetActionButtonTitle(wall));

            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);
            await _mailingService.SendEmailAsync(emailData);
        }