private void VerifyOutgoingSettings(EmailOutgoingSettings outgoingSettings) { if (string.IsNullOrWhiteSpace(outgoingSettings.ServerAddress)) { throw new BadRequestException("Please enter a mail server.", ErrorCodes.OutgoingEmptyMailServer); } if (outgoingSettings.Port < 1 || outgoingSettings.Port > 65535) { throw new BadRequestException("Ensure the port number is between 1 and 65535.", ErrorCodes.OutgoingPortOutOfRange); } if (string.IsNullOrWhiteSpace(outgoingSettings.AccountEmailAddress)) { throw new BadRequestException("Please enter the system email account address.", ErrorCodes.EmptyEmailAddress); } // Input is trimmed to be consistent with SilverLight implementation if (!EmailValidator.IsEmailAddress(outgoingSettings.AccountEmailAddress.Trim())) { throw new BadRequestException("The system email account address is not in a valid format.", ErrorCodes.InvalidEmailAddress); } if (outgoingSettings.AuthenticatedSmtp) { if (string.IsNullOrWhiteSpace(outgoingSettings.AccountUsername)) { throw new BadRequestException("Please enter the SMTP administrator username.", ErrorCodes.EmptySmtpAdministratorUsername); } if (outgoingSettings.IsPasswordDirty && string.IsNullOrWhiteSpace(outgoingSettings.AccountPassword)) { throw new BadRequestException("Please enter the SMTP administrator password.", ErrorCodes.EmptySmtpAdministratorPassword); } } }