Ejemplo n.º 1
0
        public async Task SendCommentNotificationEmailAsync(
            IProjectSettings project,
            IPost post,
            IComment comment,
            string postUrl,
            string approveUrl,
            string deleteUrl
            )
        {
            var sender = await _emailSenderResolver.GetEmailSender(project.Id);

            if (sender == null)
            {
                var logMessage = $"failed to send comment notification email because email settings are not populated for site {project.Title}";
                _log.LogError(logMessage);
                return;
            }

            if (string.IsNullOrWhiteSpace(project.CommentNotificationEmail))
            {
                var logMessage = $"failed to send comment notification email because CommentNotificationEmail is not populated for project {project.Id}";
                _log.LogError(logMessage);
                return;
            }


            var model   = new CommentNotificationModel(project, post, comment, postUrl);
            var subject = "Blog comment: " + post.Title;

            string plainTextMessage = null;
            string htmlMessage      = null;

            try
            {
                try
                {
                    htmlMessage
                        = await _viewRenderer.RenderViewAsString <CommentNotificationModel>("CommentEmail", model);
                }
                catch (Exception ex)
                {
                    _log.LogError("error generating html email from razor template", ex);
                    return;
                }

                await sender.SendEmailAsync(
                    project.CommentNotificationEmail, //to
                    null,                             //from
                    subject,
                    plainTextMessage,
                    htmlMessage,
                    comment.Email, //replyto
                    configLookupKey : project.Id
                    ).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _log.LogError($"error sending comment notification email {ex.Message} : {ex.StackTrace}");
            }
        }
        public async Task SendCommentNotificationEmailAsync(
            IProjectSettings project,
            IPost post,
            IComment comment,
            string postUrl,
            string approveUrl,
            string deleteUrl
            )
        {
            var smtpOptions = GetSmptOptions(project);

            if (smtpOptions == null)
            {
                var logMessage = $"failed to send comment notification email because smtp settings are not populated for project {project.Id}";
                log.LogError(logMessage);
                return;
            }

            if (string.IsNullOrWhiteSpace(project.CommentNotificationEmail))
            {
                var logMessage = $"failed to send comment notification email because CommentNotificationEmail is not populated for project {project.Id}";
                log.LogError(logMessage);
                return;
            }

            if (string.IsNullOrWhiteSpace(project.EmailFromAddress))
            {
                var logMessage = $"failed to send comment notification email because EmailFromAddress is not populated for project {project.Id}";
                log.LogError(logMessage);
                return;
            }

            var model   = new CommentNotificationModel(project, post, comment, postUrl);
            var subject = "Blog comment: " + post.Title;

            string plainTextMessage = null;
            string htmlMessage      = null;
            var    sender           = new EmailSender();

            try
            {
                try
                {
                    htmlMessage
                        = await viewRenderer.RenderViewAsString <CommentNotificationModel>("CommentEmail", model);
                }
                catch (Exception ex)
                {
                    log.LogError("error generating html email from razor template", ex);
                    return;
                }

                await sender.SendEmailAsync(
                    smtpOptions,
                    project.CommentNotificationEmail, //to
                    project.EmailFromAddress,         //from
                    subject,
                    plainTextMessage,
                    htmlMessage,
                    comment.Email //replyto
                    ).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                log.LogError("error sending comment notification email", ex);
            }
        }