private void SendMentionEmails(NewlyCreatedPostDTO post, List <ApplicationUser> mentionedUsers, ApplicationUser postCreator, Organization organization) { var messageBody = _markdownConverter.ConvertToHtml(_postService.GetPostBody(post.Id)); var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName); var postUrl = _appSettings.WallPostUrl(organization.ShortName, post.Id); var subject = $"You have been mentioned in the post"; foreach (var mentionedUser in mentionedUsers) { try { if (mentionedUser.NotificationsSettings != null && !mentionedUser.NotificationsSettings.MentionEmailNotifications) { continue; } var newMentionTemplateViewModel = new NewMentionTemplateViewModel( mentionedUser.FullName, postCreator.FacebookEmail, postUrl, userNotificationSettingsUrl, messageBody); var content = _mailTemplate.Generate(newMentionTemplateViewModel, EmailTemplateCacheKeys.NewMention); var emailData = new EmailDto(mentionedUser.Email, subject, content); _mailingService.SendEmail(emailData); } catch (Exception e) { _logger.Debug(e.Message, e); } } }
private async Task SendMentionEmailsAsync(NewlyCreatedPostDto post, IEnumerable <ApplicationUser> mentionedUsers, ApplicationUser postCreator, Organization organization) { var messageBody = _markdownConverter.ConvertToHtml(await _postService.GetPostBodyAsync(post.Id)); var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName); var postUrl = _appSettings.WallPostUrl(organization.ShortName, post.Id); const string subject = "You have been mentioned in the post"; foreach (var mentionedUser in mentionedUsers) { try { if (mentionedUser.NotificationsSettings?.MentionEmailNotifications == false) { continue; } var newMentionTemplateViewModel = new NewMentionTemplateViewModel(mentionedUser.FullName, postCreator.FacebookEmail, postUrl, userNotificationSettingsUrl, messageBody); var content = _mailTemplate.Generate(newMentionTemplateViewModel, EmailTemplateCacheKeys.NewMention); var emailData = new EmailDto(mentionedUser.Email, subject, content); await _mailingService.SendEmailAsync(emailData); } catch (Exception e) { _logger.Debug(e.Message, e); } } }