Ejemplo n.º 1
0
        public void NewComment(Guid itemId)
        {
            return;

            var model = new NewCommentEmailModel()
            {
            };
            var result = GetSender().ComposeEmail("NewComment", model);
            //result.Mail.To.Add(MailSender.MailSettings.AdminEmail);
            //result.Mail.Subject = Text.ComplainEmailSubject;
            //result.SendAsync();
        }
Ejemplo n.º 2
0
        public async Task <bool> SendNewCommentEmail(string authorEmail, string authorName, string commenterName, string articleTopic, string articleSlug, Func <bool> canNotifyUser)
        {
            _logger.LogInformation("Sending new comment email");

            if (!canNotifyUser())
            {
                _logger.LogInformation("User has not consented to receiving emails, email not sent");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(authorEmail))
            {
                _logger.LogWarning("Missing parameter {Parameter}, new comment email not sent", nameof(authorEmail));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(authorName))
            {
                _logger.LogWarning("Missing parameter {Parameter}, new comment email not sent", nameof(authorName));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(commenterName))
            {
                _logger.LogWarning("Missing parameter {Parameter}, new comment email not sent", nameof(commenterName));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(articleTopic))
            {
                _logger.LogWarning("Missing parameter {Parameter}, new comment email not sent", nameof(articleTopic));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(articleSlug))
            {
                _logger.LogWarning("Missing parameter {Parameter}, new comment email not sent", nameof(articleSlug));
                return(false);
            }

            try
            {
                var model = new NewCommentEmailModel()
                {
                    BaseUrl              = _url,
                    Title                = "CoreWiki Notification",
                    AuthorName           = authorName,
                    CommenterDisplayName = commenterName,
                    ArticleTopic         = articleTopic,
                    ArticleUrl           = $"{_url}{articleSlug}"
                };

                var messageBody = await _emailMessageFormatter.FormatEmailMessage(
                    TemplateProvider.NewCommentEmailTemplate,
                    model);

                return(await _emailNotifier.SendEmailAsync(
                           authorEmail,
                           "Someone said something about your article",
                           messageBody));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
#if DEBUG
                throw;
#else
                return(false);
#endif
            }
        }