Set the IPGrant list for the SMTP virtual server.

    :param str addresses: A dictionary of IP + subnet pairs.
    :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist.
    :param str server: The SMTP server name.

    :return: A boolean representing whether the change succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_connection_ip_list addresses="{'127.0.0.1': '255.255.255.255'}"

def set_connection_ip_list(addresses=None, grant_by_default=False, server=_DEFAULT_SERVER):
    '''
    Set the IPGrant list for the SMTP virtual server.

    :param str addresses: A dictionary of IP + subnet pairs.
    :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist.
    :param str server: The SMTP server name.

    :return: A boolean representing whether the change succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_connection_ip_list addresses="{'127.0.0.1': '255.255.255.255'}"
    '''
    setting = 'IPGrant'
    formatted_addresses = list()

    # It's okay to accept an empty list for set_connection_ip_list,
    # since an empty list may be desirable.
    if not addresses:
        addresses = dict()
        _LOG.debug('Empty %s specified.', setting)

    # Convert addresses to the 'ip_address, subnet' format used by
    # IIsIPSecuritySetting.
    for address in addresses:
        formatted_addresses.append('{0}, {1}'.format(address.strip(),
                                                     addresses[address].strip()))

    current_addresses = get_connection_ip_list(as_wmi_format=True, server=server)

    # Order is not important, so compare to the current addresses as unordered sets.
    if set(formatted_addresses) == set(current_addresses):
        _LOG.debug('%s already contains the provided addresses.', setting)
        return True

    # First we should check GrantByDefault, and change it if necessary.
    current_grant_by_default = _get_wmi_setting('IIsIPSecuritySetting', 'GrantByDefault', server)

    if grant_by_default != current_grant_by_default:
        _LOG.debug('Setting GrantByDefault to: %s', grant_by_default)
        _set_wmi_setting('IIsIPSecuritySetting', 'GrantByDefault', grant_by_default, server)

    _set_wmi_setting('IIsIPSecuritySetting', setting, formatted_addresses, server)

    new_addresses = get_connection_ip_list(as_wmi_format=True, server=server)
    ret = set(formatted_addresses) == set(new_addresses)

    if ret:
        _LOG.debug('%s configured successfully: %s', setting, formatted_addresses)
        return ret
    _LOG.error('Unable to configure %s with value: %s', setting, formatted_addresses)
    return ret