ixes invalid registration email formats are still rejected before the user is created
All checks were successful
Dotnet build and test / build (pull_request) Successful in 10m5s
All checks were successful
Dotnet build and test / build (pull_request) Successful in 10m5s
SMTP recipient rejections are logged and treated as a soft failure instead of crashing the request
This commit is contained in:
parent
6a6cc3a967
commit
40437982eb
2 changed files with 85 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using MailKit.Net.Smtp;
|
||||
using MailKit.Security;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
@ -114,7 +115,7 @@ namespace Yavsc.Services
|
|||
msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId(
|
||||
siteSettings.Authority
|
||||
);
|
||||
using ISmtpClient sc = _smtpClientFactory.CreateClient();
|
||||
using Yavsc.Interfaces.ISmtpClient sc = _smtpClientFactory.CreateClient();
|
||||
{
|
||||
sc.Timeout = 30000;
|
||||
sc.Connect(
|
||||
|
|
@ -139,6 +140,11 @@ namespace Yavsc.Services
|
|||
logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail);
|
||||
return string.Empty;
|
||||
}
|
||||
catch (SmtpCommandException ex)
|
||||
{
|
||||
logger.LogError(ex, "SMTP rejected the recipient or sender address. To={To}, Subject={Subject}, Status={Status}, Error={Error}", email, subject, ex.StatusCode, ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to send email. To={To}, Subject={Subject}", email, subject);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue