public async Task SendPingNotificationAsync(PingbackHistory model) { if (!IsEnabled) { _logger.LogWarning($"Skipped {nameof(SendPingNotificationAsync)} because Email sending is disabled."); await Task.CompletedTask; return; } try { var req = new PingNotificationPayload( model.TargetPostTitle, model.PingTimeUtc, model.Domain, model.SourceIp, model.SourceUrl, model.SourceTitle); await SendNotificationRequest(new NotificationRequest <PingNotificationPayload>(MailMesageTypes.BeingPinged, req)); } catch (Exception e) { _logger.LogError(e, e.Message); } }
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."); } }
public async Task <Response> SavePingbackRecord(string domain, string sourceUrl, string sourceTitle, Guid targetPostId, string targetPostTitle, string sourceIp) { try { var pid = Guid.NewGuid(); var rpb = new PingbackHistory { Domain = domain, SourceIp = sourceIp, Id = pid, PingTimeUtc = DateTime.UtcNow, SourceTitle = sourceTitle, SourceUrl = sourceUrl, TargetPostId = targetPostId, TargetPostTitle = targetPostTitle, Direction = "INBOUND" }; _pingbackRepository.Add(rpb); await NotifyAdminForReceivedPing(pid); return(new SuccessResponse()); } catch (Exception e) { Logger.LogError(e, $"Error {nameof(SavePingbackRecord)}"); return(new FailedResponse((int)ResponseFailureCode.GeneralException)); } }
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); } }