Beispiel #1
0
 /// <summary>
 /// 验证数据
 /// </summary>
 /// <param name="message"></param>
 private void CheckMailMessage(MailMessage message)
 {
     if (message == null)
     {
         throw new InfoMissingException("MailMessage");
     }
     if (message.From == null)
     {
         throw new InfoMissingException("From");
     }
     if (message.DisplayFrom == null)
     {
         message.DisplayFrom = message.From;
     }
     if (message.Tos.Count < 1)
     {
         throw new InfoMissingException("To");
     }
     try
     {
         if (System.Text.Encoding.GetEncoding(message.Encoding) == null)
         {
             throw new InfoMissingException("Encoding");
         }
     }
     catch
     {
         throw new InfoMissingException("Encoding");
     }
     foreach (var account in message.Tos)
     {
         if (!CommonValidator.CheckEmail(account.MailAddress))
         {
             throw new EmailAddressNotValidatorException();
         }
     }
     foreach (var account in message.CCs)
     {
         if (!CommonValidator.CheckEmail(account.MailAddress))
         {
             throw new EmailAddressNotValidatorException();
         }
     }
     foreach (var fileName in message.Attachment)
     {
         if (!CommonValidator.CheckFile(fileName))
         {
             throw new AttchmentException("附件不正确");
         }
     }
     if (!CommonValidator.CheckEmail(message.From.MailAddress))
     {
         throw new EmailAddressNotValidatorException();
     }
 }