Error sending mail

When trying to use the Admin panel, I see an error in the logs but it isn’t very clear on what went wrong when attempting to send mail.

Is there a debug option I can enable to better see what happened? Below is the output from the logs.

When trying to use the Admin panel, I see an error in the logs but it isn’t very clear on what went wrong when attempting to send mail.

Is there a debug option I can enable to better see what happened? Below is the output from the logs and the config.

Config

[email protected]
globalSettings__mail__smtp__host=mail.mymailhost.com
[email protected]
globalSettings__mail__smtp__password=xxxxxxxxxx
globalSettings__mail__smtp__ssl=true
globalSettings__mail__smtp__port=465
globalSettings__mail__smtp__useDefaultCredentials=false
globalSettings__disableUserRegistration=false
[email protected],[email protected]

Logs:

2018-07-05T19:59:00.810502965Z info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
2018-07-05T19:59:00.810744157Z Request starting HTTP/1.0 POST http://localhost/admin/login application/x-www-form-urlencoded 220
2018-07-05T19:59:02.193973221Z info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
2018-07-05T19:59:02.194037373Z Executing action method Bit.Admin.Controllers.LoginController.Index (Admin) with arguments (Bit.Admin.Models.LoginModel) - ModelState is Valid
2018-07-05T19:59:03.176595586Z fail: Bit.Core.Services.BackupMailService[0]
2018-07-05T19:59:03.176644177Z Error sending mail with primary service, using backup.
2018-07-05T19:59:03.176655703Z System.InvalidOperationException: Cannot find compilation library location for package ‘Microsoft.Win32.Registry’
2018-07-05T19:59:03.190145171Z at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List1 assemblies) 2018-07-05T19:59:03.204650658Z at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths() 2018-07-05T19:59:03.214673078Z at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()
2018-07-05T19:59:03.214722604Z at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly)
2018-07-05T19:59:03.214736247Z at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()
2018-07-05T19:59:03.214744952Z at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()
2018-07-05T19:59:03.214753167Z at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
2018-07-05T19:59:03.214761819Z at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(GeneratedRazorTemplate razorTemplate)
2018-07-05T19:59:03.214769412Z at RazorLight.TemplateFactoryProvider.CreateFactory(GeneratedRazorTemplate razorTemplate)
2018-07-05T19:59:03.214777269Z at RazorLight.TemplateFactoryProvider.d__4.MoveNext()
2018-07-05T19:59:03.214785730Z — End of stack trace from previous location where exception was thrown —
2018-07-05T19:59:03.214793740Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-07-05T19:59:03.214801224Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-07-05T19:59:03.214808973Z at RazorLight.RazorLightEngine.d__10.MoveNext()
2018-07-05T19:59:03.214816867Z — End of stack trace from previous location where exception was thrown —
2018-07-05T19:59:03.214850232Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-07-05T19:59:03.214860890Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-07-05T19:59:03.214868367Z at RazorLight.RazorLightEngine.d__9.MoveNext()
2018-07-05T19:59:03.214875308Z — End of stack trace from previous location where exception was thrown —
2018-07-05T19:59:03.214882196Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-07-05T19:59:03.214889161Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-07-05T19:59:03.214895731Z at Bit.Core.Services.RazorMailService.d__15.MoveNext() in /Users/kyle/Projects/bitwarden/core/src/Core/Services/Implementations/RazorMailService.cs:line 221
2018-07-05T19:59:03.214907997Z — End of stack trace from previous location where exception was thrown —
2018-07-05T19:59:03.214916138Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-07-05T19:59:03.214922985Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-07-05T19:59:03.214929933Z at Bit.Core.Services.BackupMailService.d__14.MoveNext() in /Users/kyle/Projects/bitwarden/core/src/Core/Services/Implementations/BackupMailService.cs:line 160
2018-07-05T19:59:03.680819610Z info: Microsoft.AspNetCore.Mvc.RedirectToActionResult[1]
2018-07-05T19:59:03.693288679Z Executing RedirectResult, redirecting to /admin/login?success=If%20a%20valid%20admin%20user%20with%20this%20email%20address%20exists,%20we%27ve%20sent%20you%20an%20email%20with%20a%20secure%20link%20to%20log%20in…
2018-07-05T19:59:03.715687411Z info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
2018-07-05T19:59:03.715933358Z Executed action Bit.Admin.Controllers.LoginController.Index (Admin) in 1647.8731ms
2018-07-05T19:59:03.805976914Z info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
2018-07-05T19:59:03.806062946Z Request finished in 3064.0703ms 302
2018-07-05T19:59:04.014925521Z info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
2018-07-05T19:59:04.039834002Z Request starting HTTP/1.0 GET http://localhost/admin/login?success=If%20a%20valid%20admin%20user%20with%20this%20email%20address%20exists,%20we’ve%20sent%20you%20an%20email%20with%20a%20secure%20link%20to%20log%20in.
2018-07-05T19:59:04.134899038Z info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
2018-07-05T19:59:04.166686997Z Executing action method Bit.Admin.Controllers.LoginController.Index (Admin) with arguments (, , If a valid admin user with this email address exists, we’ve sent you an email with a secure link to log in., False) - ModelState is Valid
2018-07-05T19:59:04.576213962Z info: Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor[1]
2018-07-05T19:59:04.576330997Z Executing ViewResult, running view at path /Views/Login/Index.cshtml.
2018-07-05T19:59:05.627417833Z info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
2018-07-05T19:59:05.627467379Z Executed action Bit.Admin.Controllers.LoginController.Index (Admin) in 1518.0396ms
2018-07-05T19:59:05.643989649Z info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
2018-07-05T19:59:05.659519604Z Request finished in 1628.3609ms 200 text/html; charset=utf-8
2018-07-05T20:01:14.014150932Z fail: Bit.Core.Services.SmtpMailDeliveryService[0]
2018-07-05T20:01:14.014185427Z Mail send failed.
2018-07-05T20:01:14.014190472Z System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was:
2018-07-05T20:01:14.017414980Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-07-05T20:01:14.017467495Z at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
2018-07-05T20:01:14.024018861Z at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
2018-07-05T20:01:14.024048531Z at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)

I updated the mail server to use since I was using the incorrect server but sending mail still does not occur. I am currently verifying with my hosting provider that everything is working as it should be.

2018-07-09 05:35:41.892 +00:00 [Error] Error sending mail with primary service, using backup.
System.InvalidOperationException: Cannot find compilation library location for package ‘Microsoft.Win32.Registry’
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List1 assemblies) at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()
at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly)
at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()
at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(GeneratedRazorTemplate razorTemplate)
at RazorLight.TemplateFactoryProvider.CreateFactory(GeneratedRazorTemplate razorTemplate)
at RazorLight.TemplateFactoryProvider.d__4.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.d__10.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.d__9.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Bit.Core.Services.RazorMailService.d__15.MoveNext() in /Users/kyle/Projects/bitwarden/core/src/Core/Services/Implementations/RazorMailService.cs:line 221
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Bit.Core.Services.BackupMailService.d__14.MoveNext() in /Users/kyle/Projects/bitwarden/core/src/Core/Services/Implementations/BackupMailService.cs:line 160
2018-07-09 05:37:51.976 +00:00 [Error] Mail send failed.
System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)

I have now confirmed with 2 different providers, SendGrid and my web hosting provider, that I am able to send mail without issue through them. I sent mail through both providers encrypted (TLS/SSL). My next test will be to try and send mail unencrypted by changing the port.

So far this looks like it may be issue already opened, https://github.com/bitwarden/core/issues/237

Try TLS, works for me. Otherwise check your firewall or something for outgoing ports.

I more so suspect the issue is with Bitwarden at this point. Using the same username/password (yes, base64 encoded), hostname and port (465) I am able to use openssl to connect and then send mail manually which Bitwarden doesn’t appear to handle well.

Leaving everything else the same, I change the port to 587 and Bitwarden begins sending mail without issue.

I don’t believe that this is a configuration issue on my end because both of the providers I used state to use for 465 for encrypted sessions and port 587 for unencrypted sessions.