Exemple #1
0
        public async Task <Response> SendTestNotificationAsync()
        {
            try
            {
                if (IsEnabled)
                {
                    _logger.LogInformation("Sending test mail");

                    var pipeline = new TemplatePipeline().Map(nameof(Environment.MachineName), Environment.MachineName)
                                   .Map(nameof(EmailHelper.Settings.SmtpServer), EmailHelper.Settings.SmtpServer)
                                   .Map(nameof(EmailHelper.Settings.SmtpServerPort), EmailHelper.Settings.SmtpServerPort)
                                   .Map(nameof(EmailHelper.Settings.SmtpUserName), EmailHelper.Settings.SmtpUserName)
                                   .Map(nameof(EmailHelper.Settings.EmailDisplayName), EmailHelper.Settings.EmailDisplayName)
                                   .Map(nameof(EmailHelper.Settings.EnableSsl), EmailHelper.Settings.EnableSsl);

                    await EmailHelper.ApplyTemplate(MailMesageTypes.TestMail.ToString(), pipeline)
                    .SendMailAsync(_blogConfig.EmailSettings.AdminEmail);

                    return(new SuccessResponse());
                }

                return(new FailedResponse((int)ResponseFailureCode.EmailSendingDisabled, "Email sending is disabled."));
            }
            catch (Exception e)
            {
                _logger.LogError(e, nameof(SendTestNotificationAsync));
                return(new FailedResponse((int)ResponseFailureCode.GeneralException)
                {
                    Exception = e,
                    Message = e.Message
                });
            }
        }
Exemple #2
0
        public async Task <Response> TestSendTestMailAsync()
        {
            try
            {
                Logger.LogInformation("Sending test mail");

                var pipeline = new TemplatePipeline().Map(nameof(Environment.MachineName), Environment.MachineName)
                               .Map(nameof(EmailHelper.Settings.SmtpServer), EmailHelper.Settings.SmtpServer)
                               .Map(nameof(EmailHelper.Settings.SmtpServerPort), EmailHelper.Settings.SmtpServerPort)
                               .Map(nameof(EmailHelper.Settings.SmtpUserName), EmailHelper.Settings.SmtpUserName)
                               .Map(nameof(EmailHelper.Settings.EmailDisplayName), EmailHelper.Settings.EmailDisplayName)
                               .Map(nameof(EmailHelper.Settings.EnableSsl), EmailHelper.Settings.EnableSsl);
                if (_blogConfig.EmailConfiguration.EnableEmailSending && !BlockEmailSending)
                {
                    await EmailHelper.ApplyTemplate(MailMesageType.TestMail, pipeline)
                    .SendMailAsync(_blogConfig.EmailConfiguration.AdminEmail);

                    return(new SuccessResponse());
                }

                return(new FailedResponse((int)ResponseFailureCode.EmailSendingDisabled));
            }
            catch (Exception e)
            {
                Logger.LogError(e, nameof(TestSendTestMailAsync));
                return(new FailedResponse((int)ResponseFailureCode.GeneralException)
                {
                    Exception = e,
                    Message = e.Message
                });
            }
        }
Exemple #3
0
        public async Task SendCommentReplyNotification(CommentReplySummary model, string postLink)
        {
            if (string.IsNullOrWhiteSpace(model.Email))
            {
                return;
            }

            if (model.PubDateUTC != null)
            {
                Logger.LogInformation("Sending AdminReplyNotification mail");

                var pipeline = new TemplatePipeline().Map("ReplyTime",
                                                          Utils.UtcToZoneTime(model.ReplyTimeUtc.GetValueOrDefault(), AppSettings.TimeZone))
                               .Map(nameof(model.ReplyContent), model.ReplyContent)
                               .Map("RouteLink", postLink)
                               .Map("PostTitle", model.Title)
                               .Map(nameof(model.CommentContent), model.CommentContent);

                if (_blogConfig.EmailConfiguration.EnableEmailSending && !BlockEmailSending)
                {
                    await EmailHelper.ApplyTemplate(MailMesageType.AdminReplyNotification, pipeline)
                    .SendMailAsync(model.Email);
                }
            }
        }
Exemple #4
0
        public async Task SendPingNotification(PingbackHistory receivedPingback)
        {
            var post = _postRepository.Get(receivedPingback.TargetPostId);

            if (null != post)
            {
                Logger.LogInformation($"Sending BeingPinged mail for post id {receivedPingback.TargetPostId}");

                var postTitle = post.Title;
                var pipeline  = new TemplatePipeline().Map("Title", postTitle)
                                .Map("PingTime", receivedPingback.PingTimeUtc)
                                .Map("SourceDomain", receivedPingback.Domain)
                                .Map(nameof(receivedPingback.SourceIp), receivedPingback.SourceIp)
                                .Map(nameof(receivedPingback.SourceTitle), receivedPingback.SourceTitle)
                                .Map(nameof(receivedPingback.SourceUrl), receivedPingback.SourceUrl)
                                .Map(nameof(receivedPingback.Direction), receivedPingback.Direction);

                if (_blogConfig.EmailConfiguration.EnableEmailSending && !BlockEmailSending)
                {
                    await EmailHelper.ApplyTemplate(MailMesageType.BeingPinged, pipeline)
                    .SendMailAsync(_blogConfig.EmailConfiguration.AdminEmail);
                }
            }
            else
            {
                Logger.LogWarning($"Post id {receivedPingback.TargetPostId} not found, skipping sending ping notification email.");
            }
        }
Exemple #5
0
        public static async Task TestSendTestMail(string toAddress)
        {
            var pipeline = new TemplatePipeline().Map("MachineName", Environment.MachineName)
                           .Map("SmtpServer", EmailHelper.Settings.SmtpServer)
                           .Map("SmtpServerPort", EmailHelper.Settings.SmtpServerPort)
                           .Map("SmtpUserName", EmailHelper.Settings.SmtpUserName)
                           .Map("EmailDisplayName", EmailHelper.Settings.EmailDisplayName)
                           .Map("EnableSsl", EmailHelper.Settings.EnableSsl);

            await EmailHelper.ApplyTemplate("TestMail", pipeline).SendMailAsync(toAddress);
        }
Exemple #6
0
    public async Task SendCommentReplyNotificationAsync(CommentReplyPayload request)
    {
        _logger.LogInformation("Sending AdminReplyNotification mail");

        SetEmailInfo();

        var pipeline = new TemplatePipeline().Map(nameof(request.ReplyContentHtml), request.ReplyContentHtml)
                       .Map("RouteLink", request.PostLink)
                       .Map("PostTitle", request.Title)
                       .Map(nameof(request.CommentContent), request.CommentContent);

        await EmailHelper.ApplyTemplate(MailMesageTypes.AdminReplyNotification.ToString(), pipeline)
        .SendMailAsync(request.Email);
    }
Exemple #7
0
    public async Task SendNewCommentNotificationAsync(NewCommentPayload request)
    {
        _logger.LogInformation("Sending NewCommentNotification mail");

        SetEmailInfo();

        var pipeline = new TemplatePipeline().Map(nameof(request.Username), request.Username)
                       .Map(nameof(request.Email), request.Email)
                       .Map(nameof(request.IpAddress), request.IpAddress)
                       .Map(nameof(request.CreateOnUtc), request.CreateOnUtc.ToString("MM/dd/yyyy HH:mm"))
                       .Map(nameof(request.PostTitle), request.PostTitle)
                       .Map(nameof(request.CommentContent), request.CommentContent);

        await EmailHelper.ApplyTemplate(MailMesageTypes.NewCommentNotification.ToString(), pipeline)
        .SendMailAsync(AdminEmail);
    }
Exemple #8
0
    public async Task SendTestNotificationAsync()
    {
        _logger.LogInformation("Sending test mail");

        SetEmailInfo();

        var pipeline = new TemplatePipeline().Map(nameof(Environment.MachineName), Environment.MachineName)
                       .Map(nameof(EmailHelper.Settings.SmtpServer), EmailHelper.Settings.SmtpServer)
                       .Map(nameof(EmailHelper.Settings.SmtpServerPort), EmailHelper.Settings.SmtpServerPort)
                       .Map(nameof(EmailHelper.Settings.SmtpUserName), EmailHelper.Settings.SmtpUserName)
                       .Map(nameof(EmailHelper.Settings.EmailDisplayName), EmailHelper.Settings.EmailDisplayName)
                       .Map(nameof(EmailHelper.Settings.EnableSsl), EmailHelper.Settings.EnableSsl);

        await EmailHelper.ApplyTemplate(MailMesageTypes.TestMail.ToString(), pipeline)
        .SendMailAsync(AdminEmail);
    }
Exemple #9
0
    public async Task SendPingNotificationAsync(PingPayload request)
    {
        _logger.LogInformation($"Sending BeingPinged mail for post '{request.TargetPostTitle}'");

        SetEmailInfo();

        var pipeline = new TemplatePipeline().Map(nameof(request.TargetPostTitle), request.TargetPostTitle)
                       .Map(nameof(request.PingTimeUtc), request.PingTimeUtc)
                       .Map(nameof(request.Domain), request.Domain)
                       .Map(nameof(request.SourceIp), request.SourceIp)
                       .Map(nameof(request.SourceTitle), request.SourceTitle)
                       .Map(nameof(request.SourceUrl), request.SourceUrl);

        await EmailHelper.ApplyTemplate(MailMesageTypes.BeingPinged.ToString(), pipeline)
        .SendMailAsync(AdminEmail);
    }
Exemple #10
0
        public async Task SendPingNotificationAsync(PingbackHistory receivedPingback)
        {
            if (IsEnabled)
            {
                _logger.LogInformation($"Sending BeingPinged mail for post '{receivedPingback.TargetPostTitle}'");

                var pipeline = new TemplatePipeline().Map(nameof(receivedPingback.TargetPostTitle), receivedPingback.TargetPostTitle)
                               .Map(nameof(receivedPingback.PingTimeUtc), receivedPingback.PingTimeUtc)
                               .Map(nameof(receivedPingback.Domain), receivedPingback.Domain)
                               .Map(nameof(receivedPingback.SourceIp), receivedPingback.SourceIp)
                               .Map(nameof(receivedPingback.SourceTitle), receivedPingback.SourceTitle)
                               .Map(nameof(receivedPingback.SourceUrl), receivedPingback.SourceUrl);

                await EmailHelper.ApplyTemplate(MailMesageTypes.BeingPinged.ToString(), pipeline)
                .SendMailAsync(_blogConfig.EmailSettings.AdminEmail);
            }
        }
Exemple #11
0
        public async Task SendNewCommentNotificationAsync(CommentListItem comment, Func <string, string> funcCommentContentFormat)
        {
            if (IsEnabled)
            {
                _logger.LogInformation("Sending NewCommentNotification mail");

                var pipeline = new TemplatePipeline().Map(nameof(comment.Username), comment.Username)
                               .Map(nameof(comment.Email), comment.Email)
                               .Map(nameof(comment.IpAddress), comment.IpAddress)
                               .Map(nameof(comment.CreateOnUtc), comment.CreateOnUtc.ToString("MM/dd/yyyy HH:mm"))
                               .Map(nameof(comment.PostTitle), comment.PostTitle)
                               .Map(nameof(comment.CommentContent), funcCommentContentFormat(comment.CommentContent));

                await EmailHelper.ApplyTemplate(MailMesageTypes.NewCommentNotification.ToString(), pipeline)
                .SendMailAsync(_blogConfig.EmailSettings.AdminEmail);
            }
        }
Exemple #12
0
        public async Task SendNewCommentNotificationAsync(Comment comment, string postTitle)
        {
            Logger.LogInformation("Sending NewCommentNotification mail");

            var pipeline = new TemplatePipeline().Map(nameof(comment.Username), comment.Username)
                           .Map(nameof(comment.Email), comment.Email)
                           .Map(nameof(comment.IPAddress), comment.IPAddress)
                           .Map(nameof(comment.CreateOnUtc), comment.CreateOnUtc.ToString("MM/dd/yyyy HH:mm"))
                           .Map("Title", postTitle)
                           .Map(nameof(comment.CommentContent), comment.CommentContent);

            if (_blogConfig.EmailConfiguration.EnableEmailSending && !BlockEmailSending)
            {
                await EmailHelper.ApplyTemplate(MailMesageType.NewCommentNotification, pipeline)
                .SendMailAsync(_blogConfig.EmailConfiguration.AdminEmail);
            }
        }
        public async Task TestSendTestMail()
        {
            var pipeline = new TemplatePipeline().Map("MachineName", System.Environment.MachineName)
                                                 .Map("SmtpServer", EmailHelper.Settings.SmtpServer)
                                                 .Map("SmtpServerPort", EmailHelper.Settings.SmtpServerPort)
                                                 .Map("SmtpUserName", EmailHelper.Settings.SmtpUserName)
                                                 .Map("EmailDisplayName", EmailHelper.Settings.EmailDisplayName)
                                                 .Map("EnableSsl", EmailHelper.Settings.EnableSsl);
            bool isOk = true;
            EmailHelper.EmailFailed += (s, e) =>
            {
                isOk = false;
            };

            await EmailHelper.ApplyTemplate("TestMail", pipeline)
                             .SendMailAsync("*****@*****.**");

            Assert.IsTrue(isOk);
        }
Exemple #14
0
        public async Task SendCommentReplyNotificationAsync(CommentReplyDetail model, string postLink)
        {
            if (string.IsNullOrWhiteSpace(model.Email))
            {
                return;
            }

            if (IsEnabled)
            {
                _logger.LogInformation("Sending AdminReplyNotification mail");

                var pipeline = new TemplatePipeline().Map(nameof(model.ReplyContent), model.ReplyContent)
                               .Map("RouteLink", postLink)
                               .Map("PostTitle", model.Title)
                               .Map(nameof(model.CommentContent), model.CommentContent);

                await EmailHelper.ApplyTemplate(MailMesageTypes.AdminReplyNotification.ToString(), pipeline)
                .SendMailAsync(model.Email);
            }
        }