public void Validate() { if (this.Settings == null) { throw new Exception("Settings must be supplied"); } this.Settings.Validate(); this.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(this.Body)) { throw new Exception("Body must have some content"); } if (string.IsNullOrWhiteSpace(this.Subject)) { throw new Exception("Subjet must be supplied"); } this.Sender?.Validate(); this.From?.Validate(); this.To?.Validate(); this.CC?.Validate(); this.BCC?.Validate(); this.ReplyToList?.Validate(); this.Headers?.Validate(); this.Attachments?.Validate(); if (this.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"); } }