mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
Add support for international domain names (IDN) in email addresses (#1512)
* Adjust email address checking to handle unicode * ASCII only in local part * allow unicode in second-level and top-level domain * Add PunyEncoding/Decoding methods and tests * Use PunyEncoding for outbound email recipients * Use MailKit for punycode, handle edge cases * Punyencode all email addresses in mailServices * Remove punyencoding from HandlebarsMailService * Add to punyencoding tests * Use more inclusive e-mail error * Fix comment wording * Apply StrictEmail checking to emergency access invite * Remove punyDecode helper
This commit is contained in:
@ -13,6 +13,7 @@ namespace Bit.Core.Services
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly ILogger<MailKitSmtpMailDeliveryService> _logger;
|
||||
private readonly string _replyDomain;
|
||||
private readonly string _replyEmail;
|
||||
|
||||
public MailKitSmtpMailDeliveryService(
|
||||
GlobalSettings globalSettings,
|
||||
@ -22,9 +23,12 @@ namespace Bit.Core.Services
|
||||
{
|
||||
throw new ArgumentNullException(nameof(globalSettings.Mail.Smtp.Host));
|
||||
}
|
||||
if (globalSettings.Mail?.ReplyToEmail?.Contains("@") ?? false)
|
||||
|
||||
_replyEmail = CoreHelpers.PunyEncode(globalSettings.Mail?.ReplyToEmail);
|
||||
|
||||
if (_replyEmail.Contains("@"))
|
||||
{
|
||||
_replyDomain = globalSettings.Mail.ReplyToEmail.Split('@')[1];
|
||||
_replyDomain = _replyEmail.Split('@')[1];
|
||||
}
|
||||
|
||||
_globalSettings = globalSettings;
|
||||
@ -34,7 +38,7 @@ namespace Bit.Core.Services
|
||||
public async Task SendEmailAsync(Models.Mail.MailMessage message)
|
||||
{
|
||||
var mimeMessage = new MimeMessage();
|
||||
mimeMessage.From.Add(new MailboxAddress(_globalSettings.SiteName, _globalSettings.Mail.ReplyToEmail));
|
||||
mimeMessage.From.Add(new MailboxAddress(_globalSettings.SiteName, _replyEmail));
|
||||
mimeMessage.Subject = message.Subject;
|
||||
if (!string.IsNullOrWhiteSpace(_replyDomain))
|
||||
{
|
||||
@ -43,14 +47,16 @@ namespace Bit.Core.Services
|
||||
|
||||
foreach (var address in message.ToEmails)
|
||||
{
|
||||
mimeMessage.To.Add(MailboxAddress.Parse(address));
|
||||
var punyencoded = CoreHelpers.PunyEncode(address);
|
||||
mimeMessage.To.Add(MailboxAddress.Parse(punyencoded));
|
||||
}
|
||||
|
||||
if (message.BccEmails != null)
|
||||
{
|
||||
foreach (var address in message.BccEmails)
|
||||
{
|
||||
mimeMessage.Bcc.Add(MailboxAddress.Parse(address));
|
||||
var punyencoded = CoreHelpers.PunyEncode(address);
|
||||
mimeMessage.Bcc.Add(MailboxAddress.Parse(punyencoded));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user