internal void Validate() { if (To.Count == 0) { throw new ArgumentException(ErrorMessages.EmptyToRecipients); } To.Validate(); CC.Validate(); BCC.Validate(); }
public void Validate() { if (Settings == null) { throw new Exception("Settings must be supplied"); } Settings.Validate(); CleanCollections(); if (To?.Any() == false && CC?.Any() == false && BCC?.Any() == false) { throw new Exception("At lest one To, CC or BCC must be supplied"); } if (string.IsNullOrWhiteSpace(Body)) { throw new Exception("Body must have some content"); } if (string.IsNullOrWhiteSpace(Subject)) { throw new Exception("Subjet must be supplied"); } Sender?.Validate(); From?.Validate(); To?.Validate(); CC?.Validate(); BCC?.Validate(); ReplyToList?.Validate(); Headers?.Validate(); Attachments?.Validate(); if (Attachments?.Sum(s => s.Content.Length) > MAXIMUM_SUM_ATTACHMENTS_SIZE) { throw new Exception($"Total size of attachments exceeds {(20971520 / 1024) / 1024}MB"); } if (Headers?.Count > 0 && Headers.Select(s => s.Name.Trim()).Distinct(StringComparer.OrdinalIgnoreCase).Count() != Headers.Count) { throw new Exception("Duplicate email headers are not allowed"); } }