Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert Notification by Email #41

Closed
victorssr opened this issue Jul 15, 2021 · 9 comments
Closed

Alert Notification by Email #41

victorssr opened this issue Jul 15, 2021 · 9 comments

Comments

@victorssr
Copy link

victorssr commented Jul 15, 2021

Hi!

I'm not receiving the alert email notifications. I dont know if i'm missing something.

I configured the "Smtp" section in KissLog.config from Kisslog.Frontend with the correct infos and created a new alert with the "Email messages" turned on.

I know the alerts are being triggered, because i can see they in the "alerts" section of the application.

It can be a SSL configuration? Because i didn't find anything about how to configure it in documentation.

I'm using the free on-premise KissLog with AspNetCore SDK for a .Net 5.0 WebApi

@catalingavan
Copy link
Owner

catalingavan commented Jul 15, 2021

Hi Victor,

Lets try the following:

  1. Can you please double-check that the alert has the Email messages toggle activated? (sometimes the toggle might not work as expected).
    Also make sure that there is at least one email address saved under Send email to

image

  1. Go to KissLog.Frontend\Logs\, open the most recent log file, and check if there are any relevant messages / errors.
    The endpoint used for alerts should be GET /api/activeApplicationAlerts?ApplicationId=value

Thanks!

@victorssr
Copy link
Author

Hello Catalin, thanks for the fast answer.

Yes, i think it's all set about the alert configuration:
image

I think i got a relevant log.

I cleaned the log file, force a exception to send the alert, and i got to see this log on POST /api/onApplicationAlertsTriggered:

I think the relevant part is System.Net.Mail.SmtpException: Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [ROAP284CA0218.BRAP284.PROD.OUTLOOK.COM]

2021-07-15T18:52:14.1285496Z
POST /api/onApplicationAlertsTriggered
[Information]        Executing endpoint 'KissLog.Frontend.AspNetCore.Controllers.PublicRestController.OnApplicationAlertsTriggered (KissLog.Frontend.AspNetCore)'
[Information]        Route matched with {action = "OnApplicationAlertsTriggered", controller = "PublicRest"}. Executing controller action with signature System.Threading.Tasks.Task OnApplicationAlertsTriggered(KissLog.Frontend.AspNetCore.Rest.RequestParameters.OnApplicationAlertsTriggeredRequest) on controller KissLog.Frontend.AspNetCore.Controllers.PublicRestController (KissLog.Frontend.AspNetCore).
[Information]        Entity Framework Core 3.1.2 initialized 'KissLogDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
[Information]        Executed DbCommand (4ms) [Parameters=[@__id_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30']
SELECT TOP(1) [a].[Id], [a].[Application_Id], [a].[DateTimeCreated], [a].[DateTimeUpdated], [a].[Description], [a].[IsActive], [a].[JavascriptCode], [a].[LogLevel], [a].[Name], [a].[ThrottleInSeconds], [a0].[ApplicationAlert_Id], [a0].[IsActive], [a0].[To], [a1].[ApplicationAlert_Id], [a1].[Channels], [a1].[IsActive], [a2].[Id], [a2].[DateTimeCreated], [a2].[Description], [a2].[Name], [a2].[Organization_Id]
FROM [ApplicationAlert] AS [a]
LEFT JOIN [ApplicationAlertEmailNotification] AS [a0] ON [a].[Id] = [a0].[ApplicationAlert_Id]
LEFT JOIN [ApplicationAlertSlackNotification] AS [a1] ON [a].[Id] = [a1].[ApplicationAlert_Id]
LEFT JOIN [Application] AS [a2] ON [a].[Application_Id] = [a2].[Id]
WHERE [a].[Id] = @__id_0
[Information]        Executed action KissLog.Frontend.AspNetCore.Controllers.PublicRestController.OnApplicationAlertsTriggered (KissLog.Frontend.AspNetCore) in 5148.5139ms
[Information]        Executed endpoint 'KissLog.Frontend.AspNetCore.Controllers.PublicRestController.OnApplicationAlertsTriggered (KissLog.Frontend.AspNetCore)'
[Error]              Exception:
System.Net.Mail.SmtpException: Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [ROAP284CA0218.BRAP284.PROD.OUTLOOK.COM]
   at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
   at System.Net.Mail.MailCommand.EndSend(IAsyncResult result)
   at System.Net.Mail.SendMailAsyncResult.SendMailFromCompleted(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result)
   at System.Net.Mail.SmtpClient.SendMailCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at KissLog.Smtp.SmtpService.SendAsync(MailMessage mailMessage) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.Common\src\KissLog.Smtp\SmtpService.cs:line 46
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, IEnumerable`1 to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 103
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, EmailAddress to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 67
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, String to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 62
   at KissLog.Frontend.Application.ApplicationAlertsNotifications.SendEmailNotificationService.SendAsync(ApplicationAlert applicationAlert, SendNotificationsRequest request) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Application\ApplicationAlertsNotifications\SendEmailNotificationService.cs:line 65
   at KissLog.Frontend.Application.ApplicationAlertsNotifications.SendNotificationsService.SendAsync(ApplicationAlert applicationAlert, SendNotificationsRequest request) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Application\ApplicationAlertsNotifications\SendNotificationsService.cs:line 33
   at KissLog.Frontend.AspNetCore.Controllers.PublicRestController.OnApplicationAlertsTriggered(OnApplicationAlertsTriggeredRequest request) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.AspNetCore\Controllers\PublicRestController.cs:line 54
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at KissLog.AspNetCore.KissLogMiddleware.Invoke(HttpContext context) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.Sdk\src\KissLog.AspNetCore\KissLogMiddleware.cs:line 102

@catalingavan
Copy link
Owner

The error is returned from the SMTP server.
I had a quick search and it might be related to Exchange server (https://stackoverflow.com/questions/6244694/send-smtp-email-using-system-net-mail-via-exchange-online-office-365)

Which port are you using under Smtp configuration?

I think it should be one of 587 or 25.

Also, I made a small change in the SMTP code functionality.

Please go to KissLog.Frontend and make a backup of KissLog.Smtp.dll and KissLog.Smtp.pdb.

Replace the two files with the ones from the zip attachment, restart the IIS application, and try to send an email again.

KissLog.Smtp.dll.zip

If this doesn't work, I will have a look over this issue tomorrow and try to find a fix.

PS: you can trigger a test email by accessing /Admin/Emails page.

image

@victorssr
Copy link
Author

Thanks for the email tip.

I was using the 587 port, but even after changed to 25 the same error occurred.

After replacing both smtp files the error message changed to: (With both ports)

2021-07-15T19:49:05.4906409Z
POST /Admin/SendTestEmail
[Information]        Executing endpoint 'KissLog.Frontend.AspNetCore.Controllers.AdminController.SendTestEmail (KissLog.Frontend.AspNetCore)'
[Information]        Route matched with {action = "SendTestEmail", controller = "Admin"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] SendTestEmail(KissLog.Frontend.Application.ViewModels.Admin.SendTestEmailViewModel) on controller KissLog.Frontend.AspNetCore.Controllers.AdminController (KissLog.Frontend.AspNetCore).
[Information]        Executed action KissLog.Frontend.AspNetCore.Controllers.AdminController.SendTestEmail (KissLog.Frontend.AspNetCore) in 2901.2724ms
[Information]        Executed endpoint 'KissLog.Frontend.AspNetCore.Controllers.AdminController.SendTestEmail (KissLog.Frontend.AspNetCore)'
[Error]              Exception:
System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.2.252 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:A5220000, 1.36674:01000000, 1.61250:00000000, 1.45378:02000000, 1.44866:00000000, 1.36674:7A000000, 1.61250:00000000, 1.45378:05000000, 1.44866:00140000, 1.36674:0A000000, 1.61250:00000000, 1.45378:16000000, 1.44866:836B0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:9C6B0000, 1.44866:4E010000, 16.55847:05290000, 17.43559:0000000030020000000000000500000000000000, 20.52176:140FD4901B00F01F0A007985, 20.50032:140FD4908B17F01F07000000, 0.35180:1F000130, 255.23226:42000000, 255.27962:7A000000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:21000000, 0.35250:1F001336, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:62000000, 1.36674:32000000, 1.61250:00000000, 1.45378:67000000, 1.44866:01000000, 16.55847:CE000000, 17.43559:0000000080030000000000000000000000000000, 20.52176:140FD4901B00101068000000, 20.50032:140FD4908B17000071000000, 0.35180:6D000000, 255.23226:0A00B680, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:7B000000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:96000000, 0.38698:05000780, 1.41134:46000000, 0.37692:86000000, 0.37948:01000001, 5.33852:00000000534D545000000000, 7.36354:010000000000010986000000, 4.56248:DC040000, 7.40748:010000000000010B27000010, 7.57132:000000000000000002000010, 1.63016:32000000, 4.39640:DC040000, 8.45434:4F0A22C7D09E654B9E5AD333D9D5560F03000010, 1.46798:04000000, 5.10786:0000000031352E32302E343330382E3032373A524F31503135324D42323835383A30306236373735642D393333302D343331642D383064362D6636386231386539643539393A373538313200, 7.51330:844D879BC947D9080A000010, 0.39570:1F000010, 1.55954:0A000000, 0.49266:02000000, 1.33010:0A000000, 2.54258:00000000, 0.40002:07000000, 1.56562:00000000, 1.64146:32000000, 1.33010:32000000, 2.54258:DC040000, 255.1750:31010000, 255.31418:BA000000, 0.22753:03003866, 255.21817:DC040000, 0.64418:BF000000, 4.39842:DC040000, 0.41586:3F010000, 4.60547:DC040000, 0.21966:0A002D67, 4.30158:DC040000 [Hostname=RO1P152MB2858.LAMP152.PROD.OUTLOOK.COM]
   at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)
   at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
   at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)
   at System.Net.ClosableStream.Close()
   at System.Net.Mail.MailWriter.Close()
   at System.Net.Mail.SmtpClient.Complete(Exception exception, IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at KissLog.Smtp.SmtpService.SendAsync(MailMessage mailMessage) in C:\Catalin\KissLog-net\KissLog.Common\src\KissLog.Smtp\SmtpService.cs:line 49
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, IEnumerable`1 to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 103
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, EmailAddress to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 67
   at KissLog.Frontend.Emails.EmailsService.SendEmailAsync(EmailType emailType, Object model, String to, Boolean isAsync) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Emails\EmailsService.cs:line 62
   at KissLog.Frontend.Application.Services.Admin.SendTestEmailService.SendAsync(String to, EmailType emailType) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.Application\Services\Admin\SendTestEmailService.cs:line 33
   at KissLog.Frontend.AspNetCore.Controllers.AdminController.SendTestEmail(SendTestEmailViewModel model) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.AspNetCore\KissLog.Frontend\src\KissLog.Frontend.AspNetCore\Controllers\AdminController.cs:line 161
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at KissLog.AspNetCore.KissLogMiddleware.Invoke(HttpContext context) in D:\AzureDevOpsData\_UserAgents\vsts-agent-win-x64-2.153.1\_work\1\s\KissLog-net\KissLog.Sdk\src\KissLog.AspNetCore\KissLogMiddleware.cs:line 50

@catalingavan
Copy link
Owner

Hi Victor,

Thanks for all the details. I think I know what the problem is. The email "from" value is currently set to "support@kisslog.net", and Outlook does not allow using different "from" address other than the username.

More details can be found here: https://stackoverflow.com/questions/54784431/unable-to-send-smtp-mails-using-office365-settings

I will fix this by adding a new "From" property under KissLog.json \ Smtp configuration.

I will update you once this is fixed. Sorry for the trouble!

@victorssr
Copy link
Author

No problem ☺

I'll wait for the release.

Thanks for the support and all the attention.

@catalingavan
Copy link
Owner

Hi Victor,

I released a new version of KissLog on-premises package: KissLog_Package_2.1.0.zip
You can download it from here: https://kisslog.net/Overview/OnPremises

You will only have to update the KissLog.Frontend application:

  1. Stop KissLog.Frontend IIS application

  2. Make a backup of the existing KissLog.Frontend directory

  3. Delete from KissLog.Frontend folder everything but:

/KissLog.Frontend
├── _kisslogMedia\
├── Configuration\
├── appsettings.json
└── web.config
  1. Extract the contents of KissLog.Frontend.AspNetCore.zip. Chose not to override the existing files.

  2. Open Configuration\KissLog.json, and update the Smtp configuration.
    Set the "EnableSsl" and "From" properties as described in the image below:
    Update the "From" with the same SMTP username used to authenticate to the Outlook service
    (as described here: https://stackoverflow.com/questions/54784431/unable-to-send-smtp-mails-using-office365-settings)

image

  1. Start the KissLog.Frontend IIS application

Test the email functionality by accessing /Admin/Emails page.

If this doesn't fix the problem, we will continue with the troubleshooting process :)

Thanks!

@victorssr
Copy link
Author

Hi Catalin, It works now!

image

image

Thanks for everything.

I'm glad i could contribute to the project ☺

@catalingavan
Copy link
Owner

Hi Victor,
That’s great! Your feedback helped fix one more problem, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants