Open Closed

AuthServer app failing to start due to SMPT email sender #9016


User avatar
0
WaelRazouk created

We have a microservice app deployed and running normally. Sudenly AuthServer app fails to start with this repeating error

2025-03-23 16:13:02.702 +03:00 [ERR] Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult)
at System.Net.Mail.SmtpConnection.EndInitializeConnection(IAsyncResult result)
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location ---
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml, AdditionalEmailSendingArgs additionalEmailSendingArgs)
at Volo.Abp.Emailing.BackgroundEmailSendingJob.ExecuteAsync(BackgroundEmailSendingJobArgs args)
at Volo.Abp.BackgroundJobs.BackgroundJobExecuter.ExecuteAsync(JobExecutionContext context)
2025-03-23 16:13:04.749 +03:00 [WRN] We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit(https://docs.abp.io/en/abp/latest/MailKit) or other libraries instead.For more information, see https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md
2025-03-23 16:13:05.750 +03:00 [ERR] Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult)
at System.Net.Mail.SmtpConnection.EndInitializeConnection(IAsyncResult result)
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location ---
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml, AdditionalEmailSendingArgs additionalEmailSendingArgs)
at Volo.Abp.Emailing.BackgroundEmailSendingJob.ExecuteAsync(BackgroundEmailSendingJobArgs args)
at Volo.Abp.BackgroundJobs.BackgroundJobExecuter.ExecuteAsync(JobExecutionContext context)
2025-03-23 16:13:07.798 +03:00 [WRN] We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit(https://docs.abp.io/en/abp/latest/MailKit) or other libraries instead.For more information, see https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md
2025-03-23 16:13:08.802 +03:00 [ERR] Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult)
at System.Net.Mail.SmtpConnection.EndInitializeConnection(IAsyncResult result)
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location ---
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml, AdditionalEmailSendingArgs additionalEmailSendingArgs)
at Volo.Abp.Emailing.BackgroundEmailSendingJob.ExecuteAsync(BackgroundEmailSendingJobArgs args)
at Volo.Abp.BackgroundJobs.BackgroundJobExecuter.ExecuteAsync(JobExecutionContext context)
2025-03-23 16:13:10.845 +03:00 [WRN] We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit(https://docs.abp.io/en/abp/latest/MailKit) or other libraries instead.For more information, see https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md
2025-03-23 16:13:11.846 +03:00 [ERR] Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult)
at System.Net.Mail.SmtpConnection.EndInitializeConnection(IAsyncResult result)
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location ---
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml, AdditionalEmailSendingArgs additionalEmailSendingArgs)
at Volo.Abp.Emailing.BackgroundEmailSendingJob.ExecuteAsync(BackgroundEmailSendingJobArgs args)
at Volo.Abp.BackgroundJobs.BackgroundJobExecuter.ExecuteAsync(JobExecutionContext context)
2025-03-23 16:13:13.888 +03:00 [WRN] We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit(https://docs.abp.io/en/abp/latest/MailKit) or other libraries instead.For more information, see https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md
2025-03-23 16:13:14.891 +03:00 [ERR] Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult)
at System.Net.Mail.SmtpConnection.EndInitializeConnection(IAsyncResult result)
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location ---
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)
at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml, AdditionalEmailSendingArgs additionalEmailSendingArgs)
at Volo.Abp.Emailing.BackgroundEmailSendingJob.ExecuteAsync(BackgroundEmailSendingJobArgs args)
at Volo.Abp.BackgroundJobs.BackgroundJobExecuter.ExecuteAsync(JobExecutionContext context)

We didn't add any custom code to the Authserver project, Also SMPT client is not used inside AuthServer project


7 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, the error message System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it. indicates that the AuthServer application is trying to connect to an SMTP server, but the connection is being refused.

    This is likely due to having a wrong SMTP configuration in the application, and since the background jobs run over and over again when there is a problem (retry mechanism), so by any chance, can you check your SMTP configs and ensure they are correct or not?

  • User Avatar
    0
    WaelRazouk created

    can you check your SMTP configs and ensure they are correct or not?

    In which service? AuthServer project doesn't have these configs and never uses SMTP client

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, even though you mentioned that you haven't added custom code for SMTP and are not directly using SmtpClient, the ABP framework itself often uses email for various functionalities like user registration confirmation, password reset, etc.

    In debug mode, emails are logged in a txt file (under Logs folders), not sent. On the other hand, in production mode, the SMTP settings are coming from the defined configurations in the SettingManagement page. (Btw, the related module is included in the AdministrationService, where all core ABP Pro modules reside.)

    Can you check your SMTP settings are correct in there please? (you can click the test email button to try your config)

    image.png

    Here is the code, that makes the email sender log email content instead of sent it on debug mode (you can see this code in the module class of authserver module):

        private void ConfigureEmailSender(ServiceConfigurationContext context)
        {
    #if DEBUG
            context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
    #endif
        }
    
  • User Avatar
    0
    WaelRazouk created

    OK, after fixing email settings, I got another error, here is the log

    2025-03-28 12:29:49.012 +03:00 [ERR] An unhandled exception has occurred while executing the request.
    System.InvalidOperationException: When using X.509 encryption credentials, at least one of the registered certificates must be valid.
    To use key rollover, register both the new certificate and the old one in the credentials collection.
    at OpenIddict.Server.OpenIddictServerConfiguration.PostConfigure(String name, OpenIddictServerOptions options)
    at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)
    at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue()
    at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd[TArg](String name, Func3 createOptions, TArg factoryArgument)
    at Microsoft.Extensions.Options.OptionsMonitor1.Get(String name) at OpenIddict.Validation.ServerIntegration.OpenIddictValidationServerIntegrationConfiguration.Configure(OpenIddictValidationOptions options) at Microsoft.Extensions.Options.OptionsFactory1.Create(String name)
    at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
    at System.Lazy1.CreateValue() at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd[TArg](String name, Func3 createOptions, TArg factoryArgument) at Microsoft.Extensions.Options.OptionsMonitor1.Get(String name)
    at OpenIddict.Validation.OpenIddictValidationFactory.CreateTransactionAsync()
    at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandler.HandleRequestAsync()
    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context)
    at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
    2025-03-28 12:29:49.024 +03:00 [ERR] An exception was thrown attempting to execute the error handler.
    System.InvalidOperationException: When using X.509 encryption credentials, at least one of the registered certificates must be valid.
    To use key rollover, register both the new certificate and the old one in the credentials collection.
    at OpenIddict.Server.OpenIddictServerConfiguration.PostConfigure(String name, OpenIddictServerOptions options)
    at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)
    at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue()
    at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd[TArg](String name, Func3 createOptions, TArg factoryArgument)
    at Microsoft.Extensions.Options.OptionsMonitor1.Get(String name) at OpenIddict.Validation.ServerIntegration.OpenIddictValidationServerIntegrationConfiguration.Configure(OpenIddictValidationOptions options) at Microsoft.Extensions.Options.OptionsFactory1.Create(String name)
    at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
    at System.Lazy1.CreateValue() at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd[TArg](String name, Func3 createOptions, TArg factoryArgument) at Microsoft.Extensions.Options.OptionsMonitor1.Get(String name)
    at OpenIddict.Validation.OpenIddictValidationFactory.CreateTransactionAsync()
    at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandler.HandleRequestAsync()
    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context)
    at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context)
    at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
    at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at RMG.Iso20.AuthServer.Iso20AuthServerModule.<>c.<<OnApplicationInitialization>b__2_0>d.MoveNext() in /home/vsts/work/1/s/apps/auth-server/src/RMG.Iso20.AuthServer/Iso20AuthServerModule.cs:line 214
    --- End of stack trace from previous location ---
    at Volo.Abp.Studio.Client.AspNetCore.AbpStudioMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

    an issue with the certificate.
    More info:
    We are hosting Auth server project from IIS, and the certificate is generated using Let's Encrypt (gets renewed every 3 months)

    The issue seems here

    if (!hostingEnvironment.IsDevelopment())
    {
        PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
        {
            options.AddDevelopmentEncryptionAndSigningCertificate = false;
        });
    
        PreConfigure<OpenIddictServerBuilder>(serverBuilder =>
        {
            serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "00000000-0000-0000-0000-000000000000");
            serverBuilder.SetIssuer(new Uri(configuration["AuthServer:Authority"]!));
        });
    }
    

    Because when commenting this code it works fine.

    I wander how this line works
    serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "00000000-0000-0000-0000-000000000000");
    since this openiddict.pfx file is ignored from git (i.e: it doesn't exist on ther server)!!!

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    I wander how this line works
    serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "00000000-0000-0000-0000-000000000000");
    since this openiddict.pfx file is ignored from git (i.e: it doesn't exist on ther server)!!!

    Hi, you can remove it from .gitignore if you wish or run the following command on your server to have this file:

    dotnet dev-certs https -v -ep openiddict.pfx -p 00000000-0000-0000-0000-000000000000
    

    https://abp.io/docs/latest/deployment/configuring-openiddict

  • User Avatar
    0
    WaelRazouk created

    Thank you. It worked

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Thank you. It worked

    Great to hear that. Regards.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 25, 2025, 11:10