Set the value of the setting for the SMTP virtual server.

    .. note::

        The setting names are case-sensitive.

    :param str settings: A dictionary of the setting names and their values.
    :param str server: The SMTP server name.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_server_setting settings="{'MaxRecipients': '500'}"

def set_server_setting(settings, server=_DEFAULT_SERVER):
    '''
    Set the value of the setting for the SMTP virtual server.

    .. note::

        The setting names are case-sensitive.

    :param str settings: A dictionary of the setting names and their values.
    :param str server: The SMTP server name.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_server_setting settings="{'MaxRecipients': '500'}"
    '''
    if not settings:
        _LOG.warning('No settings provided')
        return False

    # Some fields are formatted like '{data}'. Salt tries to convert these to dicts
    # automatically on input, so convert them back to the proper format.
    settings = _normalize_server_settings(**settings)

    current_settings = get_server_setting(settings=settings.keys(), server=server)

    if settings == current_settings:
        _LOG.debug('Settings already contain the provided values.')
        return True

    # Note that we must fetch all properties of IIsSmtpServerSetting below, since
    # filtering for specific properties and then attempting to set them will cause
    # an error like: wmi.x_wmi Unexpected COM Error -2147352567
    with salt.utils.winapi.Com():
        try:
            connection = wmi.WMI(namespace=_WMI_NAMESPACE)
            objs = connection.IIsSmtpServerSetting(Name=server)[0]
        except wmi.x_wmi as error:
            _LOG.error('Encountered WMI error: %s', error.com_error)
        except (AttributeError, IndexError) as error:
            _LOG.error('Error getting IIsSmtpServerSetting: %s', error)

        for setting in settings:
            if six.text_type(settings[setting]) != six.text_type(current_settings[setting]):
                try:
                    setattr(objs, setting, settings[setting])
                except wmi.x_wmi as error:
                    _LOG.error('Encountered WMI error: %s', error.com_error)
                except AttributeError as error:
                    _LOG.error('Error setting %s: %s', setting, error)

    # Get the settings post-change so that we can verify tht all properties
    # were modified successfully. Track the ones that weren't.
    new_settings = get_server_setting(settings=settings.keys(), server=server)
    failed_settings = dict()

    for setting in settings:
        if six.text_type(settings[setting]) != six.text_type(new_settings[setting]):
            failed_settings[setting] = settings[setting]
    if failed_settings:
        _LOG.error('Failed to change settings: %s', failed_settings)
        return False

    _LOG.debug('Settings configured successfully: %s', settings.keys())
    return True