public void ThrowIfInvalid() { Recipients.ThrowIfNullOrEmpty(nameof(Recipients)); Subject.ThrowIfNullOrEmpty(nameof(Subject)); ViewPath.ThrowIfNullOrEmpty(nameof(ViewPath)); foreach (string recipient in Recipients) { if (!StringHelpers.IsValidEmail(recipient)) { throw new InvalidOperationException($"Email '{recipient}' is invalid"); } } if (Cc.Any()) { foreach (string cc in Cc) { if (!StringHelpers.IsValidEmail(cc)) { throw new InvalidOperationException($"Email '{cc}' is invalid"); } } Cc = Cc.Where(x => !Recipients.Contains(x)).ToArray(); } if (HiddenCc.Any()) { foreach (string cc in HiddenCc) { if (!StringHelpers.IsValidEmail(cc)) { throw new InvalidOperationException($"Email '{cc}' is invalid"); } } HiddenCc = HiddenCc .Where(x => !Cc.Contains(x)) .Where(x => !Recipients.Contains(x)).ToArray(); } }