private string ModifyRecipient(string email) { if (this._options.Value.RecipientModifier == string.Empty) { return(email); } if (string.IsNullOrEmpty(email)) { return(email); } // Always process the emails using the specified formatter. When not wanting to send real // emails we can forward to a catch-all email address and, if supported, include the {safe-email} // value which can be used as a local part of an email (i.e. ts+{safe-email}@gmail.com). // // Prod, with no changes to the email, should just specify a empty string as the config value to ensure // no modification happens // We parse using MailAddress first to handle emails such as "Timestamp Team <*****@*****.**>" var address = new MailAddress(email).Address; var safe = address.Replace("@", "#").Replace("+", "_"); var modified = this._options.Value.RecipientModifier .Replace("{email}", email) .Replace("{safe-email}", safe); if (modified != address) { this._logger.LogDebug($"Modified email address for sending. original={address} replaced={modified}"); } // If we have not replaced the email address return the original incoming, as that may be // formatted with sender name (i.e Recruitment Genius <*****@*****.**>) return(modified); }