fortimail

FortiMail is a comprehensive email security solution by Fortinet, offering advanced threat protection, data loss prevention, encryption, and email authentication to safeguard organizations against email-based cyber threats and protect sensitive information.

Network Security · Fortimail

Details

IDfortimail
ProviderFortinet
CategoryNetwork Security
From Version6.10.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM

README

FortiMail is a comprehensive email security solution by Fortinet, offering advanced threat protection, data loss prevention, encryption, and email authentication to safeguard organizations against email-based cyber threats and protect sensitive information.
This integration was integrated and tested with version 7.4 of fortimail.

Configure FortiMail in Cortex

Parameter Required
Server URL True
Account username True
Password True
Use system proxy settings False
Trust any certificate (not secure) False

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

fortimail-ip-group-create


Create an IP group. IP group is a container that contains members of IP address that can be used when configuring access control rules (define the source IP group of the SMTP client attempting to send the email message) and IP-based policies (define the IP group of the SMTP source/destination to which the policy applies).

Base Command

fortimail-ip-group-create

Input

Argument Name Description Required
name The name of the IP group. The name must contain only alphanumeric characters. Spaces are not allowed. Required
comment A brief comment for the IP group. Optional

Context Output

Path Type Description
FortiMail.IPGroup.comment String A brief comment for the IP group.
FortiMail.IPGroup.mkey String The name of the IP group.

Command example

!fortimail-ip-group-create name=TestT

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "comment": "",
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group created successfully

mkey
TestT

fortimail-ip-group-update


Update the comment of an IP group.

Base Command

fortimail-ip-group-update

Input

Argument Name Description Required
name The name of the IP group to update. Use fortimail-ip-group-list to retrieve all the IP groups. Required
comment A brief comment for the IP group. Required

Context Output

Path Type Description
FortiMail.IPGroup.comment String A brief comment for the IP group.
FortiMail.IPGroup.mkey String The name of the IP group.

Command example

!fortimail-ip-group-update name=TestT comment=comment

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "comment": "comment",
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group updated successfully

mkey comment
TestT comment

fortimail-ip-group-delete


Delete an IP group.

Base Command

fortimail-ip-group-delete

Input

Argument Name Description Required
name The name of the IP group to remove. Use fortimail-ip-group-list to retrieve all the IP groups. Required

Context Output

There is no context output for this command.

Command example

!fortimail-ip-group-delete name=TestT

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group deleted successfully

fortimail-ip-group-list


List IP groups. if a name is given, the command will return the information about the specified IP group.

Base Command

fortimail-ip-group-list

Input

Argument Name Description Required
name The name of the IP group to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.IPGroup.comment String A brief comment for the IP group.
FortiMail.IPGroup.mkey String The name of the IP group.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "IPGroup": [
            {
                "comment": "TEST",
                "mkey": "TAL"
            },
            {
                "comment": "",
                "mkey": "TestGroup"
            },
            {
                "comment": "comment",
                "mkey": "TestT"
            },
            {
                "comment": "",
                "mkey": "TestTs"
            },
            {
                "comment": "first test",
                "mkey": "ben_lab_new"
            },
            {
                "comment": "",
                "mkey": "ben_lavV1"
            },
            {
                "comment": "lolamarish",
                "mkey": "ben_lavV1.1"
            },
            {
                "comment": "",
                "mkey": "tal_test"
            },
            {
                "comment": "dfsdfsdf",
                "isReferenced": 5,
                "mkey": "test"
            },
            {
                "comment": "test1",
                "isReferenced": 2,
                "mkey": "test1"
            }
        ]
    }
}

Human Readable Output

Ip Group list

Name Comment
TAL TEST
TestGroup  
TestT comment
TestTs  
ben_lab_new first test
ben_lavV1  
ben_lavV1.1 lolamarish
tal_test  
test dfsdfsdf
test1 test1

fortimail-ip-group-member-add


Add an IP group member (IP/Netmask or IP range) to an IP group. An IP group member is an IP address that can be used when configuring access control rules (define the source IP group of the SMTP client attempting to send the email message) and IP-based policies (define the IP group of the SMTP source/destination to which the policy applies).

Base Command

fortimail-ip-group-member-add

Input

Argument Name Description Required
group_name The name of the IP group. Use fortimail-ip-group-list to retrieve all the IP groups. Required
ip The IP address and netmask that you want to include in the IP group. Use the netmask, the portion after the slash (/), to specify the matching subnet. For example, 10.10.10.10/24 or 172.20.130.10-172.20.130.30. Required

Context Output

Path Type Description
FortiMail.IPGroup.mkey String The name of the IP group.
FortiMail.IPGroup.Member.mkey String The name of the IP member.

Command example

!fortimail-ip-group-member-add group_name=TestT ip=2.2.2.2

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "Member": {
                "mkey": "2.2.2.2-2.2.2.2"
            },
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group Member added successfully

fortimail-ip-group-member-replace


Replace IP group members with new members. This command overwrites all the IP group members that was defined in the IP group.

Base Command

fortimail-ip-group-member-replace

Input

Argument Name Description Required
group_name The name of the IP group. Use fortimail-ip-group-create to retrieve all the IP groups. Required
ips A comma-separated list of IP address that you want to replace in the IP group. Use the netmask, the portion after the slash (/), to specify the matching subnet. For example, 10.10.10.10/24,12.12.12.12/24,172.20.130.10-172.20.130.30. Required

Context Output

There is no context output for this command.

Command example

!fortimail-ip-group-member-replace group_name=TestT ips=3.3.3.3,4.4.4.4

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "Member": [
                {
                    "mkey": "3.3.3.3-3.3.3.3"
                },
                {
                    "mkey": "4.4.4.4-4.4.4.4"
                }
            ],
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group Member replaced successfully

fortimail-ip-group-member-delete


Delete an IP group member from IP group.

Base Command

fortimail-ip-group-member-delete

Input

Argument Name Description Required
group_name The name of the IP group. Use fortimail-ip-group-list to retrieve all the IP groups. Required
ip The IP address member to remove from the IP group. Use fortimail-ip-group-member-list to retrieve all the IP group members. Required

Context Output

There is no context output for this command.

Command example

!fortimail-ip-group-member-delete group_name=TestT ip=4.4.4.4

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "mkey": "4.4.4.4"
        }
    }
}

Human Readable Output

Ip Group Member deleted successfully

fortimail-ip-group-member-list


List IP group members. If an ip is given, the command will return the information about the specified IP group member.

Base Command

fortimail-ip-group-member-list

Input

Argument Name Description Required
group_name The name of the IP group. Use fortimail-ip-group-list to retrieve all the IP groups. Required
ip The IP address that you want to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.IPGroup.mkey String The name of the IP group.
FortiMail.IPGroup.Member.mkey String The name of the IP member.

Command example

!fortimail-ip-group-member-list group_name=TestT

Context Example

{
    "FortiMail": {
        "IPGroup": {
            "Member": [
                {
                    "mkey": "3.3.3.3-3.3.3.3"
                }
            ],
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Ip Group Member

Name Group Name
3.3.3.3-3.3.3.3 TestT

fortimail-email-group-create


Create an email group. An email group is a container for a list of email addresses, allowing you to use it in configuring access control rules (for defining the sender and recipient matching) and recipient-based policies (for defining MAIL FROM addresses matching specific policies).

Base Command

fortimail-email-group-create

Input

Argument Name Description Required
name The name of the email group. The name must contain only alphanumeric characters. Spaces are not allowed. Required
comment A brief comment for the email group. Optional

Context Output

Path Type Description
FortiMail.EmailGroup.comment String A brief comment for the email group.
FortiMail.EmailGroup.mkey String The name of the email group.

Command example

!fortimail-email-group-create name=TestT

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "comment": "",
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group created successfully

mkey
TestT

fortimail-email-group-update


Update the comment of an email group.

Base Command

fortimail-email-group-update

Input

Argument Name Description Required
name The name of the email group to update. Use fortimail-email-group-list to retrieve all the email groups. Required
comment A brief comment for the email group. Required

Context Output

Path Type Description
FortiMail.EmailGroup.comment String A brief comment for the email group.
FortiMail.EmailGroup.mkey String The name of the email group.

Command example

!fortimail-email-group-update name=TestT comment=comment

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "comment": "comment",
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group updated successfully

mkey comment
TestT comment

fortimail-email-group-delete


Delete an email group.

Base Command

fortimail-email-group-delete

Input

Argument Name Description Required
name The name of the email group to remove. Use fortimail-email-group-list to retrieve all the email groups. Required

Context Output

There is no context output for this command.

Command example

!fortimail-email-group-delete name=TestT

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group deleted successfully

fortimail-email-group-list


List email groups. If a name is given, the command will return the information about the specified email group.

Base Command

fortimail-email-group-list

Input

Argument Name Description Required
name The name of the email group to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.EmailGroup.comment String A brief comment for the email group.
FortiMail.EmailGroup.mkey String The name of the email group.

Command example

Human Readable Output

Email Group list

Name Comment
TestT comment
new_version3242342.0 new_comment_update
test  

fortimail-email-group-member-add


Add an email group member (email address) to an email group.

Base Command

fortimail-email-group-member-add

Input

Argument Name Description Required
group_name The name of the email group. Use fortimail-email-group-list to retrieve all the email groups. Required
email The email address that you want to include in the email group. For example, example@example.com. You can also use wildcards to enter partial patterns that can match multiple email addresses. The asterisk represents one or more characters and the question mark (?) represents any single character. For example, the pattern ??@*.com will match any email user with a two letter email user name from any “.com” domain name. Required

Context Output

Path Type Description
FortiMail.EmailGroup.mkey String The name of the email group.
FortiMail.EmailGroup.Member.mkey String The name of the email member.

Command example

!fortimail-email-group-member-add group_name=TestT email=t@t.com

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "Member": {
                "mkey": "t@t.com"
            },
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group Member added successfully

fortimail-email-group-member-replace


Replace email group members with new members. This command overwrites all the email group members that were defined in the email group.

Base Command

fortimail-email-group-member-replace

Input

Argument Name Description Required
group_name The name of the email group. Use fortimail-email-group-list to retrieve all the email groups. Required
emails A comma-separated list of email address that you want to replace in the email group. For example, test1@test.com,test2@test.com. You can also use wildcards to enter partial patterns that can match multiple email addresses. The asterisk represents one or more characters and the question mark (?) represents any single character. For example, the pattern ??@*.com will match any email user with a two letter email user name from any “.com” domain name. Required

Context Output

There is no context output for this command.

Command example

!fortimail-email-group-member-replace group_name=TestT emails=d@d.com,r@r.com

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "Member": [
                {
                    "mkey": "d@d.com"
                },
                {
                    "mkey": "r@r.com"
                }
            ],
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group Member replaced successfully

fortimail-email-group-member-delete


Delete an email group member from an email group.

Base Command

fortimail-email-group-member-delete

Input

Argument Name Description Required
group_name The name of the email group. Use fortimail-email-group-list to retrieve all the email groups. Required
email The email member to remove from the email group. Use fortimail-email-group-member-list to retrieve all the email members. Required

Context Output

There is no context output for this command.

Command example

!fortimail-email-group-member-delete group_name=TestT email=r@r.com

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "mkey": "r@r.com"
        }
    }
}

Human Readable Output

Email Group Member deleted successfully

fortimail-email-group-member-list


List email group members. If an email is given, the command will return the information about the specified email group member.

Base Command

fortimail-email-group-member-list

Input

Argument Name Description Required
group_name The name of the email group. Use fortimail-email-group-list to retrieve all the email groups. Required
email The email member to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.EmailGroup.mkey String The name of the email group.
FortiMail.EmailGroup.Member.mkey String The name of the email member.

Command example

!fortimail-email-group-member-list group_name=TestT

Context Example

{
    "FortiMail": {
        "EmailGroup": {
            "Member": [
                {
                    "mkey": "d@d.com"
                }
            ],
            "mkey": "TestT"
        }
    }
}

Human Readable Output

Email Group Member

Name Group Name
d@d.com TestT

fortimail-system-safe-block-list


List the system Block/Safe list. Choose the specified list by the type argument.

Base Command

fortimail-system-safe-block-list

Input

Argument Name Description Required
list_type The type of the list to retrieve. Possible values are: Blocklist, Safelist. Required
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.SystemList.item String The value of the item in the list.
FortiMail.SystemList.list_type String The type of the list (safelist or blocklist).

Command example

!fortimail-system-safe-block-list list_type=Blocklist

Context Example

{
    "FortiMail": {
        "SystemList": [
            {
                "item": "1.1.1.1/24",
                "list_type": "Blocklist"
            },
            {
                "item": "1.1.1.5/24",
                "list_type": "Blocklist"
            },
            {
                "item": "1.1.5.5/24",
                "list_type": "Blocklist"
            },
            {
                "item": "1.1.5.6/24",
                "list_type": "Blocklist"
            },
            {
                "item": "1.2.2.1/24",
                "list_type": "Blocklist"
            },
            {
                "item": "1.2.5.6/24",
                "list_type": "Blocklist"
            },
            {
                "item": "3.5.7.8/24",
                "list_type": "Blocklist"
            },
            {
                "item": "5.5.5.5/24",
                "list_type": "Blocklist"
            },
            {
                "item": "7.7.7.7/24",
                "list_type": "Blocklist"
            }
        ]
    }
}

Human Readable Output

System Safe Block

item list_type
1.1.1.1/24 Blocklist
1.1.1.5/24 Blocklist
1.1.5.5/24 Blocklist
1.1.5.6/24 Blocklist
1.2.2.1/24 Blocklist
1.2.5.6/24 Blocklist
3.5.7.8/24 Blocklist
5.5.5.5/24 Blocklist
7.7.7.7/24 Blocklist

fortimail-system-safe-block-add


Add an email address/ domain name/ IP address to the system safe/block list. Block/Safe List lets you reject, discard, or allow email messages based on email addresses, domain names, and IP addresses. As one of the first steps to detect spam, FortiMail units evaluate whether an email message matches a block list or safe list entry. Choose the specified list by the type argument.

Base Command

fortimail-system-safe-block-add

Input

Argument Name Description Required
values Email address/ domain name/ IP address to add to the system safe/block list. The supported entry types are Email (For example, example@example.com, @example.com), IP/Netmask: (For example, 10.10.10.10/24), and Reverse DNS (For example, http://example.com. You can use the following wild cards:: Matches any number of characters. You can use the asterisk (*) anywhere in a character string.?: Matches a single alphabet in a specific position. Required
list_type The type of the list to add the values. Safelist - accept message. Blocklist - invoke block list action that was defined in the settings. Possible values are: Blocklist, Safelist. Required

Context Output

There is no context output for this command.

Command example

!fortimail-system-safe-block-add values=1.1.1.1 list_type=Blocklist

Context Example

{
    "FortiMail": {
        "SystemSafeBlock": {
            "item": "1.1.1.1",
            "list_type": "Blocklist"
        }
    }
}

Human Readable Output

System Block List Items Was Added Successfully

item list_type
1.1.1.1 Blocklist

fortimail-system-safe-block-delete


Delete an email address/ domain name/ IP address from the system safe/block list. Choose the specified list by the type argument.

Base Command

fortimail-system-safe-block-delete

Input

Argument Name Description Required
values A comma-separated list of email addresses/ domain names/ IP addresses to remove from the system safe/block list. For example, test@test.com, test2@test.com or 1.1.1.1/0,1.1.1.2/0. Use system-safe-block-list to get all safe/block list values. Required
list_type The type of the list to add the values. Safelist - accept message. Blocklist - invoke block list action that was defined in the settings. Possible values are: Blocklist, Safelist. Required

Context Output

There is no context output for this command.

Command example

!fortimail-system-safe-block-delete values=1.1.1.1 list_type=Blocklist

Context Example

{
    "FortiMail": {
        "SystemList": {
            "mkey": "Blocklist"
        }
    }
}

Human Readable Output

System Safe Block deleted successfully

fortimail-ip-policy-create


Create an IP policy. IP-based policies lets you control emails based on IP/Netmask / IP Group/ GeoIP Group/ ISDB.

Base Command

fortimail-ip-policy-create

Input

Argument Name Description Required
status Whether to apply the policy. Possible values are: enable, disable. Default is enable. Optional
source The source of the policy. When source_type is IP/Netmask, enter the IP address and subnet mask of the SMTP client to whose connections this policy will apply. When source_type is IP Group, enter the IP group of the SMTP client to whose connections this policy will apply (use fortimail-ip-group-list to retrieve all the IP groups). When source_type is GeoIP, enter the Geo IP group. When source_type is ISDB, enter the name of an internet service provider. To match all clients, enter 0.0.0.0/0. Default is 0.0.0.0/0. Optional
destination The destination of the policy. When destination_type is IP/Netmask, enter the IP address and subnet mask of the SMTP client to whose connections this policy will apply. When destination_type is IP Group, enter the IP group of the SMTP client to whose connections this policy will apply (use fortimail-ip-group-list to retrieve all the IP groups). To match all clients, enter 0.0.0.0/0. Default is 0.0.0.0/0. Optional
source_type The type of the source. Insert the source argument corresponding to the type value. Possible values are: IP/Netmask, IP Group, GeoIP Group, ISDB. Default is IP/Netmask. Optional
destination_type The type of the destination. Insert the source argument corresponding to the type value. Possible values are: IP/Netmask, IP Group. Default is IP/Netmask. Optional
action An action for the policy. Proxy-bypass: Bypass the FortiMail unit’s scanning. This action is for transparent mode only.Scan: Accept the connection and perform any scans configured in the profiles selected in this policy. Reject: Reject the email and respond to the SMTP client with SMTP reply code 550, indicating a permanent failure. Fail Temporarily: Reject the email and respond to the SMTP client with SMTP reply code 451, indicating a temporary failure. Possible values are: Scan, Reject, Fail Temporarily, Proxy bypass. Default is Scan. Optional
comment A brief comment for the IP policy. Optional
session_profile The name of the session profile that you want to apply to connections matching the policy. Use fortimail-session-profile-list to retrieve all the session profiles. This option is applicable only if action is Scan. Optional
antispam_profile The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles. This option is applicable only if action is Scan. Optional
antivirus_profile The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles. This option is applicable only if action is Scan. Optional
content_profile The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles. This option is applicable only if action is Scan. Optional
ip_pool_profile The name of an IP pool profile, if any, that this policy will apply.The IP addresses in the IP pool are used as the source IP address for the SMTP sessions matching this policy.An IP pool in an IP policy will be used to deliver incoming email from FortiMail to the protected server. An IP pool (either in an IP policy or domain settings) will be used to deliver emails to the protected domain servers if the mail flow is from internal to internal domains. Use fortimail-ip-pool-list to retrieve all the IP pool profiles. Optional
auth_type The type of the authentication profile that this policy will apply. If you want the email user to authenticate using an external authentication server, select the authentication type of the profile (SMTP, POP3, IMAP, RADIUS, or LDAP). Possible values are: imap, ldap, pop3, radius, smpt. Optional
auth_profile The name of an authentication profile for the type. When auth_type is LDAP, insert LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. When auth_type is RADIUS, insert RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles. When auth_type is POP3, insert POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles. When auth_type is IMAP, insert IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles. When auth_type is SMTP, insert SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles. Relevant when auth_type is chosen. Optional
use_smtp_auth Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data. This option is available only if you have selected an auth_profile. Possible values are: enable, disable. Default is disable. Optional
smtp_different Whether to require that the sender uses the same identity for: authentication name, SMTP envelope MAIL FROM:, and header FROM:. Possible values are: enable, disable. Default is disable. Optional
smtp_diff_identity_ldap Whether to verify SMTP sender identity with LDAP for authenticated email. Possible values are: enable, disable. Default is disable. Optional
smtp_diff_identity_ldap_profile LDAP profile for SMTP sender identity verification. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. Required when smtp_diff_identity_ldap is enable. Optional
exclusive Whether to take precedence over recipient-based policy match. Enable to omit use of recipient-based policies for connections matching this IP-based policy. This option is applicable only if action is Scan. Possible values are: enable, disable. Default is disable. Optional

Context Output

Path Type Description
FortiMail.IPPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.IPPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.IPPolicy.smtp_different String ‘Whether to require that the sender uses the same identity for: authentication name, SMTP envelope MAIL FROM:, and header FROM:.’
FortiMail.IPPolicy.use_smtp_auth String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.IPPolicy.action String The action of the policy.
FortiMail.IPPolicy.comment String A brief comment for the IP policy.
FortiMail.IPPolicy.exclusive Boolean Whether to take precedence over recipient-based policy match.
FortiMail.IPPolicy.smtp_auth String The authentication profile when auth_type=SMTP.
FortiMail.IPPolicy.imap_auth String The authentication profile when auth_type=IMAP.
FortiMail.IPPolicy.pop3_auth String The authentication profile when auth_type=POP3.
FortiMail.IPPolicy.ldap_auth String The authentication profile when auth_type=LDAP.
FortiMail.IPPolicy.radius_auth String The authentication profile when auth_type=RADIUS.
FortiMail.IPPolicy.auth_type String The type of the authentication profile that this policy will apply. If you want the email user to authenticate using an external authentication server, select the authentication type of the profile (SMTP, POP3, IMAP, RADIUS, or LDAP).
FortiMail.IPPolicy.ip_pool_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.content_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.antivirus_profile String The name of an antivirus profile, if any, that this policy will apply.
FortiMail.IPPolicy.antispam_profile String The name of an outgoing anti-spam profile, if any, that this policy apply.
FortiMail.IPPolicy.session_profile String The name of the session profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.status String Whether the policy applied.
FortiMail.IPPolicy.server_ip_group String The destination IP group. Relevant when server_type is IP group.
FortiMail.IPPolicy.server String The destination IP/Netmask. Relevant when server_type is IP/Netmask.
FortiMail.IPPolicy.server_type String The type of the destination.
FortiMail.IPPolicy.client_isdb String The source ISDB. Relevant when client_type is ISDB.
FortiMail.IPPolicy.client_ip_group String The source IP group. Relevant when client_type is IP group.
FortiMail.IPPolicy.client_geoip_group String The Geo IP group. Relevant when client_type is Geo IP.
FortiMail.IPPolicy.client String The source IP/Netmask. Relevant when client_type is IP/Netmask.
FortiMail.IPPolicy.client_type String The type of the source.
FortiMail.IPPolicy.mkey Number The ID of the IP policy.

Command example

!fortimail-ip-policy-create status=enable comment=testTal

Context Example

{
    "FortiMail": {
        "IPPolicy": {
            "action": "Scan",
            "antispam_profile": "",
            "antivirus_profile": "",
            "client": "0.0.0.0/0",
            "client_geoip_group": "0.0.0.0/0",
            "client_ip_group": "0.0.0.0/0",
            "client_isdb": "0.0.0.0/0",
            "client_type": "IP/Netmask",
            "comment": "testTal",
            "content_profile": "",
            "exclusive": "disable",
            "imap_auth": "",
            "ip_pool_profile": "",
            "ldap_auth": "",
            "mkey": 1,
            "pop3_auth": "",
            "profile_dlp": "",
            "radius_auth": "",
            "server": "0.0.0.0/0",
            "server_ip_group": "0.0.0.0/0",
            "server_type": "IP/Netmask",
            "session_profile": "",
            "smtp_auth": "",
            "smtp_diff_identity_ldap": "disable",
            "smtp_diff_identity_ldap_profile": "",
            "smtp_different": "disable",
            "status": "enable",
            "use_smtp_auth": "disable"
        }
    }
}

Human Readable Output

Ip Policy created successfully

Action Action On Failure Client Client Type Comment Name Server Server Type Status
Scan Scan 0.0.0.0/0 IP/Netmask testTal 1 0.0.0.0/0 IP/Netmask enable

fortimail-ip-policy-update


Update an IP policy.

Base Command

fortimail-ip-policy-update

Input

Argument Name Description Required
ip_policy_id The ID of the IP policy. Required
status Whether to apply the policy. Possible values are: enable, disable. Default is enable. Optional
source The source of the policy. When source_type is IP/Netmask, enter the IP address and subnet mask of the SMTP client to whose connections this policy will apply. When source_type is IP Group, enter the IP group of the SMTP client to whose connections this policy will apply (use fortimail-ip-group-list to retrieve all the IP groups). When source_type is GeoIP, enter the Geo IP group. When source_type is ISDB, enter the name of an internet service provider. To match all clients, enter 0.0.0.0/0. Optional
destination The destination of the policy. When destination_type is IP/Netmask, enter the IP address and subnet mask of the SMTP client to whose connections this policy will apply. When destination_type is IP Group, enter the IP group of the SMTP client to whose connections this policy will apply (use fortimail-ip-group-list to retrieve all the IP groups). To match all clients, enter 0.0.0.0/0. Optional
source_type The type of the source. Insert the source argument corresponding to the type value. Possible values are: IP/Netmask, IP Group, GeoIP Group, ISDB. Optional
destination_type The type of the destination. Insert the source argument corresponding to the type value. Possible values are: IP/Netmask, IP Group. Optional
action An action for the policy. Proxy-bypass: Bypass the FortiMail unit’s scanning. This action is for transparent mode only.Scan: Accept the connection and perform any scans configured in the profiles selected in this policy. Reject: Reject the email and respond to the SMTP client with SMTP reply code 550, indicating a permanent failure. Fail Temporarily: Reject the email and respond to the SMTP client with SMTP reply code 451, indicating a temporary failure. Possible values are: Scan, Reject, Fail Temporarily, Proxy bypass. Optional
comment A brief comment for the IP policy. Optional
session_profile The name of the session profile that you want to apply to connections matching the policy. Use fortimail-session-profile-list to retrieve all the session profiles. This option is applicable only if action is Scan. Optional
antispam_profile The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles. This option is applicable only if action is Scan. Optional
antivirus_profile The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles. This option is applicable only if action is Scan. Optional
content_profile The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles. This option is applicable only if action is Scan. Optional
ip_pool_profile The name of an IP pool profile, if any, that this policy will apply.The IP addresses in the IP pool are used as the source IP address for the SMTP sessions matching this policy.An IP pool in an IP policy will be used to deliver incoming email from FortiMail to the protected server. An IP pool (either in an IP policy or domain settings) will be used to deliver emails to the protected domain servers if the mail flow is from internal to internal domains. Use fortimail-ip-pool-list to retrieve all the IP pool profiles. Optional
auth_type The type of the authentication profile that this policy will apply. If you want the email user to authenticate using an external authentication server, select the authentication type of the profile (SMTP, POP3, IMAP, RADIUS, or LDAP). Possible values are: imap, ldap, pop3, radius, smpt. Optional
auth_profile The name of an authentication profile for the type. When auth_type is LDAP, insert LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. When auth_type is RADIUS, insert RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles. When auth_type is POP3, insert POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles. When auth_type is IMAP, insert IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles. When auth_type is SMTP, insert SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles. Relevant when auth_type is chosen. Optional
use_smtp_auth Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data. This option is available only if you have selected an auth_profile. Possible values are: enable, disable. Optional
smtp_different Whether to require that the sender uses the same identity for: authentication name, SMTP envelope MAIL FROM:, and header FROM:. Possible values are: enable, disable. Optional
smtp_diff_identity_ldap Whether to verify SMTP sender identity with LDAP for authenticated email. Possible values are: enable, disable. Optional
smtp_diff_identity_ldap_profile LDAP profile for SMTP sender identity verification. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. Required when smtp_diff_identity_ldap is enable. Optional
exclusive Whether to take precedence over recipient-based policy match. Enable to omit use of recipient-based policies for connections matching this IP-based policy. This option is applicable only if action is Scan. Possible values are: enable, disable. Optional

Context Output

Path Type Description
FortiMail.IPPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.IPPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.IPPolicy.smtp_different String ‘Whether to require that the sender uses the same identity for: authentication name, SMTP envelope MAIL FROM:, and header FROM:.’
FortiMail.IPPolicy.use_smtp_auth String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.IPPolicy.action String The action of the policy.
FortiMail.IPPolicy.comment String A brief comment for the IP policy.
FortiMail.IPPolicy.exclusive Boolean Whether to take precedence over recipient-based policy match.
FortiMail.IPPolicy.smtp_auth String The authentication profile when auth_type=SMTP.
FortiMail.IPPolicy.imap_auth String The authentication profile when auth_type=IMAP.
FortiMail.IPPolicy.pop3_auth String The authentication profile when auth_type=POP3.
FortiMail.IPPolicy.ldap_auth String The authentication profile when auth_type=LDAP.
FortiMail.IPPolicy.radius_auth String The authentication profile when auth_type=RADIUS.
FortiMail.IPPolicy.auth_type String The type of the authentication profile that this policy will apply. If you want the email user to authenticate using an external authentication server, select the authentication type of the profile (SMTP, POP3, IMAP, RADIUS, or LDAP).
FortiMail.IPPolicy.ip_pool_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.content_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.antivirus_profile String The name of an antivirus profile, if any, that this policy will apply.
FortiMail.IPPolicy.antispam_profile String The name of an outgoing anti-spam profile, if any, that this policy apply.
FortiMail.IPPolicy.session_profile String The name of the session profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.status String Whether the policy applied.
FortiMail.IPPolicy.server_ip_group String The destination IP group. Relevant when server_type is IP group.
FortiMail.IPPolicy.server String The destination IP/Netmask. Relevant when server_type is IP/Netmask.
FortiMail.IPPolicy.server_type String The type of the destination.
FortiMail.IPPolicy.client_isdb String The source ISDB. Relevant when client_type is ISDB.
FortiMail.IPPolicy.client_ip_group String The source IP group. Relevant when client_type is IP group.
FortiMail.IPPolicy.client_geoip_group String The Geo IP group. Relevant when client_type is Geo IP.
FortiMail.IPPolicy.client String The source IP/Netmask. Relevant when client_type is IP/Netmask.
FortiMail.IPPolicy.client_type String The type of the source.
FortiMail.IPPolicy.mkey Number The ID of the IP policy.

Command example

!fortimail-ip-policy-update ip_policy_id=4 comment=test2

Context Example

{
    "FortiMail": {
        "IPPolicy": {
            "comment": "test2",
            "mkey": 4,
            "status": "enable"
        }
    }
}

Human Readable Output

Ip Policy updated successfully

Comment Name Status
test2 4 enable

fortimail-ip-policy-move


Move an IP policy location in the policy list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

Base Command

fortimail-ip-policy-move

Input

Argument Name Description Required
policy_id The ID of the IP policy rule to be moved. Use fortimail-ip-policy-list to retrieve all the access control. Required
reference_id The reference ID of the IP policy rule when moving before/after. Required when action is before/ after. Optional
action The move action. When using before/ after, insert reference_id. Possible values are: up, down, before, after. Required

Context Output

There is no context output for this command.

Command example

!fortimail-ip-policy-move policy_id=4 action=up

Human Readable Output

Ip Policy moved successfully

fortimail-ip-policy-delete


Delete an IP policy.

Base Command

fortimail-ip-policy-delete

Input

Argument Name Description Required
policy_id The ID of the IP policy to remove. Use fortimail-ip-policy-list to retrieve all the access control. Required

Context Output

There is no context output for this command.

Command example

!fortimail-ip-policy-delete policy_id=9

Context Example

{
    "FortiMail": {
        "IPPolicy": {
            "mkey": "9"
        }
    }
}

Human Readable Output

Ip Policy deleted successfully

fortimail-ip-policy-list


List an IP policy. If an ID is given, the command will return the information about the specified IP policy.

Base Command

fortimail-ip-policy-list

Input

Argument Name Description Required
policy_id The ID of the IP policy to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.IPPolicy.status String Whether the policy applied.
FortiMail.IPPolicy.client_type String The type of the source.
FortiMail.IPPolicy.client String The source IP/Netmask. Relevant when client_type is IP/Netmask.
FortiMail.IPPolicy.client_ip_group String The source IP group. Relevant when client_type is IP group.
FortiMail.IPPolicy.client_geoip_group String The Geo IP group. Relevant when client_type is Geo IP.
FortiMail.IPPolicy.client_isdb String The source ISDB. Relevant when client_type is ISDB.
FortiMail.IPPolicy.server_type String The type of the destination.
FortiMail.IPPolicy.server String The destination IP/Netmask. Relevant when server_type is IP/Netmask.
FortiMail.IPPolicy.server_ip_group String The destination IP group. Relevant when server_type is IP group.
FortiMail.IPPolicy.action String The action of the policy.
FortiMail.IPPolicy.comment String A brief comment for the IP policy.
FortiMail.IPPolicy.session_profile String The name of the session profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.antispam_profile String The name of an outgoing anti-spam profile, if any, that this policy apply.
FortiMail.IPPolicy.antivirus_profile String The name of an antivirus profile, if any, that this policy will apply.
FortiMail.IPPolicy.content_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.ip_pool_profile String The name of the content profile that you want to apply to connections matching the policy.
FortiMail.IPPolicy.auth_type String The type of the authentication profile that this policy will apply. If you want the email user to authenticate using an external authentication server, select the authentication type of the profile (SMTP, POP3, IMAP, RADIUS, or LDAP).
FortiMail.IPPolicy.smtp_auth String The authentication profile when auth_type=SMTP.
FortiMail.IPPolicy.imap_auth String The authentication profile when auth_type=IMAP.
FortiMail.IPPolicy.pop3_auth String The authentication profile when auth_type=POP3.
FortiMail.IPPolicy.ldap_auth String The authentication profile when auth_type=LDAP.
FortiMail.IPPolicy.radius_auth String The authentication profile when auth_type=RADIUS.
FortiMail.IPPolicy.use_smtp_auth String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.IPPolicy.smtp_different String ‘Whether to require that the sender uses the same identity for: authentication name, SMTP envelope MAIL FROM:, and header FROM:.’
FortiMail.IPPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.IPPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.IPPolicy.exclusive Boolean Whether to take precedence over recipient-based policy match.
FortiMail.IPPolicy.mkey Number The ID of the IP policy.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "IPPolicy": [
            {
                "antispam_profile": "",
                "antivirus_profile": "",
                "client": "0.0.0.0/0",
                "client_geoip_group": "",
                "client_ip_group": "",
                "client_isdb": "",
                "client_type": "IP/Netmask",
                "comment": "testTal",
                "content_profile": "",
                "exclusive": "disable",
                "imap_auth": "",
                "ip_pool_profile": "",
                "ldap_auth": "",
                "mkey": 1,
                "pop3_auth": "",
                "profile_dlp": "",
                "radius_auth": "",
                "server": "0.0.0.0/0",
                "server_ip_group": "",
                "session_profile": "",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam_profile": "",
                "antivirus_profile": "",
                "client": "0.0.0.0/0",
                "client_geoip_group": "",
                "client_ip_group": "",
                "client_isdb": "",
                "client_type": "IP/Netmask",
                "comment": "",
                "content_profile": "",
                "exclusive": "disable",
                "imap_auth": "",
                "ip_pool_profile": "",
                "ldap_auth": "",
                "mkey": 3,
                "pop3_auth": "",
                "profile_dlp": "",
                "radius_auth": "",
                "server": "0.0.0.0/0",
                "server_ip_group": "",
                "session_profile": "",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam_profile": "",
                "antivirus_profile": "",
                "client": "0.0.0.0/0",
                "client_geoip_group": "",
                "client_ip_group": "",
                "client_isdb": "",
                "client_type": "IP/Netmask",
                "comment": "test2",
                "content_profile": "",
                "exclusive": "disable",
                "imap_auth": "",
                "ip_pool_profile": "",
                "ldap_auth": "",
                "mkey": 4,
                "pop3_auth": "",
                "profile_dlp": "",
                "radius_auth": "",
                "server": "0.0.0.0/0",
                "server_ip_group": "",
                "session_profile": "",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam_profile": "",
                "antivirus_profile": "",
                "client": "0.0.0.0/0",
                "client_geoip_group": "",
                "client_ip_group": "",
                "client_isdb": "",
                "client_type": "IP/Netmask",
                "comment": "s",
                "content_profile": "",
                "exclusive": "disable",
                "imap_auth": "",
                "ip_pool_profile": "",
                "ldap_auth": "",
                "mkey": 5,
                "pop3_auth": "",
                "profile_dlp": "",
                "radius_auth": "",
                "server": "0.0.0.0/0",
                "server_ip_group": "",
                "session_profile": "",
                "smtp_auth": "",
                "status": "enable"
            }
        ]
    }
}

Human Readable Output

Ip Policy list

Name Comment Server Client Client Type Status
1 testTal 0.0.0.0/0 0.0.0.0/0 IP/Netmask enable
3   0.0.0.0/0 0.0.0.0/0 IP/Netmask enable
4 test2 0.0.0.0/0 0.0.0.0/0 IP/Netmask enable
5 s 0.0.0.0/0 0.0.0.0/0 IP/Netmask enable

fortimail-access-control-create


Create an Access control rule. Access control rules take effect after the FortiMail unit has initiated or received an IP and TCP-level connection at the application layer of the network.

Base Command

fortimail-access-control-create

Input

Argument Name Description Required
status Whether to activate the access rule. Possible values are: enable, disable. Default is enable. Optional
sender_type The method of the SMTP client attempting to send the email message. Select either User Defined and enter a complete or partial sender email address to match, or select: Internal: Match any email address from a protected domain. External: Match any email address from an unprotected domain. Email Group: Match any email address in the group. If you select this option, in the sender argument insert an email group. LDAP Group: Match any email address in the group. If you select this option, in the sender_ldap_profile argument insert an LDAP profile and in sender insert an LDAP group name. LDAP Verification: Match any individual email address queried by the LDAP profile. If you select this option, in the sender_ldap_profile argument insert an LDAP profile. Regular Expression: Use regular expression syntax instead of wildcards to specify the pattern. User Defined: Specify the email addresses. The pattern can use wildcards or regular expressions. Possible values are: External, Internal, Email Group, LDAP Group, LDAP Verification, Regular Expression, User Defined. Default is User Defined. Optional
sender The sender. Relevant when sender_type is not External or Internal. When sender_type = Email Group, insert email group (use fortimail-email-group-list to retrieve all the email groups). When sender_type = LDAP Verification, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When sender_type= LDAP Group, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When sender_type = Regular Expression or User Defined, insert a pattern that defines recipient email addresses which match this rule, surrounded in slashes and single quotes (such as '' ). Default is. Optional
recipient_type The recipient pattern type. Either select User Defined and enter a complete or partial recipient email address to match, or select: Internal: Match any email address from a protected domain. External: Match any email address from a domain that is not protected. Email Group: Match any email address in the group. If you select this option, in the recipient argument insert an email group. LDAP Group: Match any email address in the group. If you select this option, in the recipient_ldap_profile argument insert an LDAP profile and in the recipient insert an LDAP group name. LDAP Verification: Match any individual email address queried by the LDAP profile. If you select this option, in the recipient_ldap_profile argument insert an LDAP profile. Regular Expression: Use regular expression syntax instead of wildcards to specify the pattern. User Defined: Specify the email addresses. The pattern can use wildcards or regular expressions. Possible values are: External, Internal, Email Group, LDAP Group, LDAP Verification, Regular Expression, User Defined. Default is User Defined. Optional
recipient The recipient. Relevant when recipient_type is not External or Internal. When recipient_type= Email Group, insert email group (use fortimail-email-group-list to retrieve all the email groups). When recipient_type= LDAP Verification, insert LDAP server. When recipient_type= LDAP Group, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When recipient_type= Regular Expression or User Defined, insert a pattern that defines recipient email addresses which match this rule, surrounded in slashes and single quotes (such as '' ). Default is. Optional
sender_ldap_profile Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when sender_type= LDAP Group. Optional
recipient_ldap_profile Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group. Optional
source_type The method of the SMTP client attempting to send the email message. Possible values are: IP/Netmask, IP Group, GeoIP Group, ISDB. Default is IP/Netmask. Optional
source When sender_type = IP/Netmask insert the source IP address and netmask of the SMTP client attempting to send the email message. Use the netmask, the portion after the slash (/), to specify the matching subnet. When sender_type = IP Group, insert email group (use fortimail-ip-group-list to retrieve all the IP Groups). When sender_type = GeoIP Group, insert a Geo IP group (use fortimail-geoip-group-list to retrieve all the Geo IP groups)When sender_type = ISDB, insert an ISDB. Default is 0.0.0.0/0. Optional
reverse_dns_pattern A pattern to compare to the result of a reverse DNS look-up of the source IP address of the SMTP client attempting to send the email message. Default is *. Optional
reverse_dns_pattern_regex Whether to use regular expression syntax instead of wildcards to specify the reverse DNS pattern. Possible values are: enable, disable. Optional
authentication_status Authentication status. Indicate whether this rule applies only to messages delivered by clients that have authenticated with the FortiMail unit. any: Match or do not match this access control rule regardless of whether the client has authenticated with the FortiMail unit. authenticated: Match this access control rule only for clients that have authenticated with the FortiMail unit. not-authenticated: Match this access control rule only for clients that have not authenticated with the FortiMail unit. Possible values are: Any, Authenticated, Not Authenticated. Default is Any. Optional
tls_profile A TLS profile to allow or reject the connection based on whether the communication session attributes match the settings in the TLS profile. If matching, then perform the access control rule action {discard | receive | reject | relay | safe | safe-relay}. If not matching, then perform the TLS profile failure action instead. Use fortimail-tls-profile-list to retrieve all the TLS profiles. Optional
action The delivery action that FortiMail unit will perform for SMTP sessions matching this access control rule. reject: Reject delivery of the email (SMTP reply code 550 Relaying denied).discard: Accept the email (SMTP reply code 250 OK), but then silently delete it and do not deliver it. relay:Accept the email (SMTP reply code 250 OK), regardless of authentication or protected domain. Do not greylist, but continue with remaining anti-spam and other scans. If all scans pass, the email is delivered.safe: Accept the email (SMTP reply code 250 OK) if the sender authenticates or recipient belongs to a protected domain. Greylist, but skip remaining anti-spam scans and but continue with others such as antivirus.Otherwise, if the sender does not authenticate, or the recipient does not belong to a protected domain, then reject delivery of the email (SMTP reply code 554 5.7.1 Relaying denied).In older FortiMail versions, this setting was named bypass.safe-relay: Like safe, except do not greylist.receive: Like relay, except greylist, and require authentication or protected domain.Otherwise, if the sender does not authenticate or the recipient does not belong to a protected domain, then FortiMail rejects (SMTP reply code 554 5.7.1 Relaying denied).Tip: Usually, the receive action is used when you need to apply a TLS profile, but do not want to safelist nor allow outbound, which Relay does. If you do not need to apply a TLS profile, then a rule with this action is often not required because by default, email inbound to protected domains is relayed/proxied. Possible values are: Discard, Receive, Reject, Relay, Safe, Safe & Relay. Default is Reject. Optional
comment A brief comment for the Access control. Optional

Context Output

Path Type Description
FortiMail.AccessControl.comment String A brief comment for the access control.
FortiMail.AccessControl.action Number The delivery action that FortiMail unit will perform for SMTP sessions matching this access control rule.
FortiMail.AccessControl.tls_profile String A TLS profile to allow or reject the connection based on whether the communication session attributes match the settings in the TLS profile.
FortiMail.AccessControl.authenticated Number Authentication status. Indicate whether this rule applies only to messages delivered by clients that have authenticated with the FortiMail unit.
FortiMail.AccessControl.reverse_dns_pattern_regexp Number Whether to use a regular expression in the reverse DNS pastern.
FortiMail.AccessControl.reverse_dns_pattern String Whether to use regular expression syntax instead of wildcards to specify the reverse DNS pattern.
FortiMail.AccessControl.sender_ip_group String The sender IP group. Relevant when sender_type is IP Group.
FortiMail.AccessControl.sender_isdb String The sender ISDB. Relevant when sender_type is ISDB.
FortiMail.AccessControl.sender_geoip_group String The sender Geo IP group. Relevant when sender_type is Geo IP group.
FortiMail.AccessControl.sender_ip_mask String The sender IP/Netmask. Relevant when sender_type is IP address.
FortiMail.AccessControl.sender_ip_type Number ‘The sender (source) type. Optional values: IP/Netmask,IP Group,GeoIP Group,ISDB.’
FortiMail.AccessControl.recipient_pattern_ldap_groupname String Recipient pattern. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_ldap String Recipient pattern profile. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_group String Recipient email group. Relevant when recipient_pattern_type is Email Group.
FortiMail.AccessControl.recipient_pattern String Recipient pattern. Relevant when recipient_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.recipient_pattern_type Number Recipient pattern type.
FortiMail.AccessControl.sender_pattern_ldap_groupname String Sender pattern. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_ldap String Sender pattern profile. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_group String Sender email group. Relevant when sender_pattern_type is Email Group.
FortiMail.AccessControl.sender_pattern String Sender pattern. Relevant when sender_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.sender_pattern_type Number ‘Sender pattern type. Optional values: External,Internal,Email Group, LDAP Group,LDAP Verification,Regular Expression,User Defined.’
FortiMail.AccessControl.status Boolean Whether the access control is activated.
FortiMail.AccessControl.mkey Number The ID of the access control.

Command example

!fortimail-access-control-create status=enable comment=TalTest1

Context Example

{
    "FortiMail": {
        "AccessControl": {
            "action": "Reject",
            "authenticated": "Any",
            "comment": "TalTest1",
            "mkey": 3,
            "recipient_pattern": "*",
            "recipient_pattern_group": "*",
            "recipient_pattern_ldap": "",
            "recipient_pattern_ldap_groupname": "*",
            "recipient_pattern_type": "User Defined",
            "reverse_dns_pattern": "*",
            "reverse_dns_pattern_regexp": 0,
            "sender_geoip_group": "0.0.0.0/0",
            "sender_ip_group": "0.0.0.0/0",
            "sender_ip_mask": "0.0.0.0/0",
            "sender_ip_type": "IP/Netmask",
            "sender_isdb": "0.0.0.0/0",
            "sender_pattern": "*",
            "sender_pattern_group": "*",
            "sender_pattern_ldap": "",
            "sender_pattern_ldap_groupname": "*",
            "sender_pattern_type": "User Defined",
            "status": "enable",
            "tls_profile": ""
        }
    }
}

Human Readable Output

Access Control created successfully

Action Action On Failure Authenticated Comment Name Recipient Pattern Type Sender Geo IP Group Sender Ip Group Sender Ip Mask Sender Ip Type Sender Pattern Sender Pattern Type Status
Reject Reject Any TalTest1 3 User Defined 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 IP/Netmask * User Defined enable

fortimail-access-control-update


Update an access control.

Base Command

fortimail-access-control-update

Input

Argument Name Description Required
access_control_id The ID of the access control. Required
status Whether to activate the access rule. Possible values are: enable, disable. Default is enable. Optional
sender_type The method of the SMTP client attempting to send the email message. Select either User Defined and enter a complete or partial sender email address to match, or select: Internal: Match any email address from a protected domain. External: Match any email address from an unprotected domain. Email Group: Match any email address in the group. If you select this option, in the sender argument insert an email group. LDAP Group: Match any email address in the group. If you select this option, in the sender_ldap_profile argument insert an LDAP profile and in sender insert an LDAP group name. LDAP Verification: Match any individual email address queried by the LDAP profile. If you select this option, in the sender_ldap_profile argument insert an LDAP profile. Regular Expression: Use regular expression syntax instead of wildcards to specify the pattern. User Defined: Specify the email addresses. The pattern can use wildcards or regular expressions. Possible values are: External, Internal, Email Group, LDAP Group, LDAP Verification, Regular Expression, User Defined. Optional
sender The sender. Relevant when sender_type is not External or Internal. When sender_type = Email Group, insert email group (use fortimail-email-group-list to retrieve all the email groups). When sender_type = LDAP Verification, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When sender_type= LDAP Group, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When sender_type = Regular Expression or User Defined, insert a pattern that defines recipient email addresses which match this rule, surrounded in slashes and single quotes (such as '*' ). Optional
recipient_type The recipient pattern type. Either select User Defined and enter a complete or partial recipient email address to match, or select: Internal: Match any email address from a protected domain. External: Match any email address from a domain that is not protected. Email Group: Match any email address in the group. If you select this option, in the recipient argument insert an email group. LDAP Group: Match any email address in the group. If you select this option, in the recipient_ldap_profile argument insert an LDAP profile and in recipient insert an LDAP group name. LDAP Verification: Match any individual email address queried by the LDAP profile. If you select this option, in the recipient_ldap_profile argument insert an LDAP profile. Regular Expression: Use regular expression syntax instead of wildcards to specify the pattern. User Defined: Specify the email addresses. The pattern can use wildcards or regular expressions. Possible values are: External, Internal, Email Group, LDAP Group, LDAP Verification, Regular Expression, User Defined. Optional
recipient The recipient. Relevant when recipient_type is not External or Internal. When recipient_type= Email Group, insert email group (use fortimail-email-group-list to retrieve all the email groups). When recipient_type= LDAP Verification, insert LDAP server. When recipient_type= LDAP Group, insert LDAP group (use fortimail-ldap-group-list to retrieve all the LDAP groups). When recipient_type= Regular Expression or User Defined, insert a pattern that defines recipient email addresses which match this rule, surrounded in slashes and single quotes (such as '*' ). Optional
sender_ldap_profile Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when sender_type= LDAP Group. Optional
recipient_ldap_profile Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group. Optional
source_type The method of the SMTP client attempting to send the email message. Possible values are: IP/Netmask, IP Group, GeoIP Group, ISDB. Optional
source When sender_type = IP/Netmask insert the source IP address and netmask of the SMTP client attempting to send the email message. Use the netmask, the portion after the slash (/), to specify the matching subnet. When sender_type = IP Group, insert email group (use fortimail-ip-group-list to retrieve all the IP Groups). When sender_type = GeoIP Group, insert a Geo IP group. When sender_type = ISDB, insert an ISDB. Optional
reverse_dns_pattern A pattern to compare to the result of a reverse DNS look-up of the source IP address of the SMTP client attempting to send the email message. Optional
reverse_dns_pattern_regex Whether to use regular expression syntax instead of wildcards to specify the reverse DNS pattern. Possible values are: enable, disable. Optional
authentication_status Authentication status. Indicate whether this rule applies only to messages delivered by clients that have authenticated with the FortiMail unit. any: Match or do not match this access control rule regardless of whether the client has authenticated with the FortiMail unit. authenticated: Match this access control rule only for clients that have authenticated with the FortiMail unit. not-authenticated: Match this access control rule only for clients that have not authenticated with the FortiMail unit. Possible values are: Any, Authenticated, Not Authenticated. Optional
tls_profile A TLS profile to allow or reject the connection based on whether the communication session attributes match the settings in the TLS profile. If matching, then perform the access control rule action {discard | receive | reject | relay | safe | safe-relay}. If not matching, then perform the TLS profile failure action instead. Use fortimail-tls-profile-list to retrieve all the TLS profiles. Optional
action The delivery action that FortiMail unit will perform for SMTP sessions matching this access control rule:reject: Reject delivery of the email (SMTP reply code 550 Relaying denied).discard: Accept the email (SMTP reply code 250 OK), but then silently delete it and do not deliver it.relay:Accept the email (SMTP reply code 250 OK), regardless of authentication or protected domain. Do not greylist, but continue with remaining anti-spam and other scans. If all scans pass, the email is delivered.safe: Accept the email (SMTP reply code 250 OK) if the sender authenticates or recipient belongs to a protected domain. Greylist, but skip remaining anti-spam scans and but continue with others such as antivirus.Otherwise, if the sender does not authenticate, or the recipient does not belong to a protected domain, then reject delivery of the email (SMTP reply code 554 5.7.1 Relaying denied).In older FortiMail versions, this setting was named bypass.safe-relay: Like safe, except do not greylist.receive: Like relay, except greylist, and require authentication or protected domain.Otherwise, if the sender does not authenticate or the recipient does not belong to a protected domain, then FortiMail rejects (SMTP reply code 554 5.7.1 Relaying denied).Tip: Usually, the receive action is used when you need to apply a TLS profile, but do not want to safelist nor allow outbound, which Relay does. If you do not need to apply a TLS profile, then a rule with this action is often not required because by default, email inbound to protected domains is relayed/proxied. Possible values are: Discard, Receive, Reject, Relay, Safe, Safe & Relay. Optional
comment A brief comment for the Access control. Optional

Context Output

Path Type Description
FortiMail.AccessControl.comment String A brief comment for the access control.
FortiMail.AccessControl.action Number The delivery action that FortiMail unit will perform for SMTP sessions matching this access control rule.
FortiMail.AccessControl.tls_profile String A TLS profile to allow or reject the connection based on whether the communication session attributes match the settings in the TLS profile.
FortiMail.AccessControl.authenticated Number Authentication status. Indicate whether this rule applies only to messages delivered by clients that have authenticated with the FortiMail unit.
FortiMail.AccessControl.reverse_dns_pattern_regexp Number Whether to use a regular expression in the reverse DNS pastern.
FortiMail.AccessControl.reverse_dns_pattern String Whether to use regular expression syntax instead of wildcards to specify the reverse DNS pattern.
FortiMail.AccessControl.sender_ip_group String The sender IP group. Relevant when sender_type is IP Group.
FortiMail.AccessControl.sender_isdb String The sender ISDB. Relevant when sender_type is ISDB.
FortiMail.AccessControl.sender_geoip_group String The sender Geo IP group. Relevant when sender_type is Geo IP group.
FortiMail.AccessControl.sender_ip_mask String The sender IP/Netmask. Relevant when sender_type is IP address.
FortiMail.AccessControl.sender_ip_type Number ‘The sender (source) type. Optional values: IP/Netmask,IP Group,GeoIP Group,ISDB.’
FortiMail.AccessControl.recipient_pattern_ldap_groupname String Recipient pattern. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_ldap String Recipient pattern profile. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_group String Recipient email group. Relevant when recipient_pattern_type is Email Group.
FortiMail.AccessControl.recipient_pattern String Recipient pattern. Relevant when recipient_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.recipient_pattern_type Number Recipient pattern type.
FortiMail.AccessControl.sender_pattern_ldap_groupname String Sender pattern. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_ldap String Sender pattern profile. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_group String Sender email group. Relevant when sender_pattern_type is Email Group.
FortiMail.AccessControl.sender_pattern String Sender pattern. Relevant when sender_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.sender_pattern_type Number ‘Sender pattern type. Optional values: External,Internal,Email Group, LDAP Group,LDAP Verification,Regular Expression,User Defined.’
FortiMail.AccessControl.status Boolean Whether the access control is activated.
FortiMail.AccessControl.mkey Number The ID of the access control.

Command example

!fortimail-access-control-update access_control_id=1 comment=test2

Context Example

{
    "FortiMail": {
        "AccessControl": {
            "comment": "test2",
            "mkey": 1,
            "status": "enable"
        }
    }
}

Human Readable Output

Access Control updated successfully

Comment Name Status
test2 1 enable

fortimail-access-control-delete


Delete an access control rule.

Base Command

fortimail-access-control-delete

Input

Argument Name Description Required
access_control_id The ID of the access rule to remove. Use fortimail-access-control-list to retrieve all the access control. Required

Context Output

There is no context output for this command.

Command example

!fortimail-access-control-delete access_control_id=19

Context Example

{
    "FortiMail": {
        "AccessControl": {
            "mkey": "19"
        }
    }
}

Human Readable Output

Access Control deleted successfully

fortimail-access-control-move


Move an Access control rule location in the rules list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

Base Command

fortimail-access-control-move

Input

Argument Name Description Required
access_control_id The ID of the access control to be moved. Use fortimail-access-control-list to retrieve all the access control. Required
reference_id The reference ID of the access control rule when moving before/after. Optional
action The move action. Possible values are: up, down, before, after. Optional

Context Output

There is no context output for this command.

Command example

!fortimail-access-control-move access_control_id=2 action=down

Human Readable Output

Access Control moved successfully

fortimail-access-control-list


List access control rules. If an ID is given, the command will return the information about the specified access control rule.

Base Command

fortimail-access-control-list

Input

Argument Name Description Required
access_control_id The ID of the IP policy to retrieve. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.AccessControl.comment String A brief comment for the access control.
FortiMail.AccessControl.action Number The delivery action that FortiMail unit will perform for SMTP sessions matching this access control rule.
FortiMail.AccessControl.tls_profile String A TLS profile to allow or reject the connection based on whether the communication session attributes match the settings in the TLS profile.
FortiMail.AccessControl.authenticated Number Authentication status. Indicate whether this rule applies only to messages delivered by clients that have authenticated with the FortiMail unit.
FortiMail.AccessControl.reverse_dns_pattern_regexp Number Whether to use a regular expression in the reverse DNS pastern.
FortiMail.AccessControl.reverse_dns_pattern String Whether to use regular expression syntax instead of wildcards to specify the reverse DNS pattern.
FortiMail.AccessControl.sender_ip_group String The sender IP group. Relevant when sender_type is IP Group.
FortiMail.AccessControl.sender_isdb String The sender ISDB. Relevant when sender_type is ISDB.
FortiMail.AccessControl.sender_geoip_group String The sender Geo IP group. Relevant when sender_type is Geo IP group.
FortiMail.AccessControl.sender_ip_mask String The sender IP/Netmask. Relevant when sender_type is IP address.
FortiMail.AccessControl.sender_ip_type Number ‘The sender (source) type. Optional values: IP/Netmask,IP Group,GeoIP Group,ISDB.’
FortiMail.AccessControl.recipient_pattern_ldap_groupname String Recipient pattern. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_ldap String Recipient pattern profile. Relevant when recipient_pattern_type is LDAP Group.
FortiMail.AccessControl.recipient_pattern_group String Recipient email group. Relevant when recipient_pattern_type is Email Group.
FortiMail.AccessControl.recipient_pattern String Recipient pattern. Relevant when recipient_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.recipient_pattern_type Number Recipient pattern type.
FortiMail.AccessControl.sender_pattern_ldap_groupname String Sender pattern. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_ldap String Sender pattern profile. Relevant when sender_pattern_type is LDAP Group.
FortiMail.AccessControl.sender_pattern_group String Sender email group. Relevant when sender_pattern_type is Email Group.
FortiMail.AccessControl.sender_pattern String Sender pattern. Relevant when sender_pattern_type is Regular Expression or User Defined.
FortiMail.AccessControl.sender_pattern_type Number ‘Sender pattern type. Optional values: External,Internal,Email Group, LDAP Group,LDAP Verification,Regular Expression,User Defined.’
FortiMail.AccessControl.status Boolean Whether the access control is activated.
FortiMail.AccessControl.mkey Number The ID of the access control.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "AccessControl": [
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "test2",
                "mkey": 1,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "testTal",
                "mkey": 2,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "TalTest1",
                "mkey": 3,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Discard",
                "authenticated": "Any",
                "comment": "s",
                "mkey": 4,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "test",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "LDAP Verification",
                "reverse_dns_pattern": "*2323",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "test",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP Group",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "Regular Expression",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Discard",
                "authenticated": "Authenticated",
                "comment": "action 1",
                "mkey": 5,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "test",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*2323",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "Test_3",
                "sender_ip_group": "test",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "GeoIP Group",
                "sender_isdb": "8X8",
                "sender_pattern": "*",
                "sender_pattern_group": "new_version3242342.0",
                "sender_pattern_ldap": "tal",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "",
                "mkey": 6,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "disable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "",
                "mkey": 7,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Discard",
                "authenticated": "Any",
                "comment": "",
                "mkey": 8,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Discard",
                "authenticated": "Any",
                "comment": "",
                "mkey": 9,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "External",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Discard",
                "authenticated": "Any",
                "comment": "Tal",
                "mkey": 10,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "Internal",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Test",
                "mkey": 11,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "User Defined",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Test",
                "mkey": 12,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "new_version3242342.0",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "Email Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Test",
                "mkey": 13,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Test",
                "mkey": 14,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Verification",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Test",
                "mkey": 15,
                "recipient_pattern": "*",
                "recipient_pattern_group": "new_version3242342.0",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "Email Group",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Verification",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Tesffft",
                "mkey": 16,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Verification",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Tt",
                "mkey": 17,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "LDAP Verification",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Safe & Relay",
                "authenticated": "Any",
                "comment": "action 1",
                "mkey": 18,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "test",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "LDAP Verification",
                "reverse_dns_pattern": "*2323",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "test",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP Group",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "ttt",
                "sender_pattern_type": "LDAP Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Reject",
                "authenticated": "Any",
                "comment": "Talll",
                "mkey": 20,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "User Defined",
                "reverse_dns_pattern": "*",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP/Netmask",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "test_group",
                "sender_pattern_type": "LDAP Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Safe & Relay",
                "authenticated": "Any",
                "comment": "action 1",
                "mkey": 21,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "test",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "LDAP Verification",
                "reverse_dns_pattern": "*2323",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "test",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP Group",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "test",
                "sender_pattern_ldap": "",
                "sender_pattern_ldap_groupname": "",
                "sender_pattern_type": "Email Group",
                "status": "enable",
                "tls_profile": ""
            },
            {
                "action": "Safe & Relay",
                "authenticated": "Any",
                "comment": "action 33331",
                "mkey": 23,
                "recipient_pattern": "*",
                "recipient_pattern_group": "",
                "recipient_pattern_ldap": "test",
                "recipient_pattern_ldap_groupname": "",
                "recipient_pattern_type": "LDAP Verification",
                "reverse_dns_pattern": "*2323",
                "reverse_dns_pattern_regexp": 0,
                "sender_geoip_group": "",
                "sender_ip_group": "test",
                "sender_ip_mask": "0.0.0.0/0",
                "sender_ip_type": "IP Group",
                "sender_isdb": "",
                "sender_pattern": "*",
                "sender_pattern_group": "",
                "sender_pattern_ldap": "test",
                "sender_pattern_ldap_groupname": "ttt",
                "sender_pattern_type": "LDAP Group",
                "status": "enable",
                "tls_profile": ""
            }
        ]
    }
}

Human Readable Output

Access Control list

Name Comment Action On Failure Status Action Authenticated Sender Pattern Sender Pattern Type Sender Ip Type Sender Ip Group Sender Ip Mask Sender Geo IP Group Recipient Pattern Type
1 test2 Reject enable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
2 testTal Reject enable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
3 TalTest1 Reject enable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
4 s Discard enable Discard Any * Regular Expression IP Group test 0.0.0.0/0   LDAP Verification
5 action 1 Discard enable Discard Authenticated * LDAP Group GeoIP Group test 0.0.0.0/0 Test_3 User Defined
6   Reject disable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
7   Reject enable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
8   Discard enable Discard Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
9   Discard enable Discard Any * User Defined IP/Netmask   0.0.0.0/0   External
10 Tal Discard enable Discard Any * User Defined IP/Netmask   0.0.0.0/0   Internal
11 Test Reject enable Reject Any * User Defined IP/Netmask   0.0.0.0/0   User Defined
12 Test Reject enable Reject Any * Email Group IP/Netmask   0.0.0.0/0   User Defined
13 Test Reject enable Reject Any * LDAP Group IP/Netmask   0.0.0.0/0   User Defined
14 Test Reject enable Reject Any * LDAP Verification IP/Netmask   0.0.0.0/0   User Defined
15 Test Reject enable Reject Any * LDAP Verification IP/Netmask   0.0.0.0/0   Email Group
16 Tesffft Reject enable Reject Any * LDAP Verification IP/Netmask   0.0.0.0/0   User Defined
17 Tt Reject enable Reject Any * LDAP Verification IP/Netmask   0.0.0.0/0   User Defined
18 action 1 Safe & Relay enable Safe & Relay Any * LDAP Group IP Group test 0.0.0.0/0   LDAP Verification
20 Talll Reject enable Reject Any * LDAP Group IP/Netmask   0.0.0.0/0   User Defined
21 action 1 Safe & Relay enable Safe & Relay Any * Email Group IP Group test 0.0.0.0/0   LDAP Verification
23 action 33331 Safe & Relay enable Safe & Relay Any * LDAP Group IP Group test 0.0.0.0/0   LDAP Verification

fortimail-recipient-policy-create


Create an Inbound/ Outbound Recipient policy. Recipient policies control email based on sender and recipient addresses. Recipient-based policies have precedence if an IP-based policy is also applicable but conflicts.

Base Command

fortimail-recipient-policy-create

Input

Argument Name Description Required
type The mail traffic direction. Possible values are: Inbound, Outbound. Default is Inbound. Optional
status Whether to apply the policy. Possible values are: enable, disable. Default is enable. Optional
comment A brief comment for the IP policy. Optional
sender_type Define sender (MAIL FROM:) email addresses that match this policy. If you enter LDAP group, also configure sender_ldap_profile by entering an LDAP profile in which you have enabled and configured a group query. If you enter Email address group, also configure sender_email_address_group by entering an Email group in which you have enabled and configured a group query. Possible values are: User (wildcard), User (regex), LDAP group, Email address group. Optional
sender_pattern The policy sender pattern. When sender_type is User (wildcard), insert email addresses that match this policy. For example, test@test.com. When sender_type is User (regex), insert the recipient email address regular expression pattern. When sender_type is LDAP group, insert the sender pattern. When sender_type is Email address group, insert email group (use fortimail-email-group-list to retrieve all the email groups). Optional
sender_ldap_profile Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when sender_type=LDAP Group. Optional
sender_email_address_group Sender Email group (use fortimail-email-group-list to retrieve all the Email groups). Relevant when recipient_type=Email address group. Optional
recipient_type Define recipient (RCPT TO:) email addresses that match this policy. If you enter LDAP group, also configure recipient_ldap_profile by entering an LDAP profile in which you have enabled and configured a group query. If you enter Email address group, also configure recipient_email_address_group by entering an Email group in which you have enabled and configured a group query. Possible values are: User (wildcard), User (regex), LDAP group, Email address group. Optional
recipient_pattern The policy recipient pattern. When recipient_type is User (wildcard), insert the local part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy and after insert @ and the domain part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy. For example, test@test.com. When recipient_type is User (regex), insert the recipient email address regular expression pattern. When recipient_type is LDAP group, insert the sender pattern. When recipient_type is Email address group, insert email group (use fortimail-email-group-list to retrieve all the email groups). Optional
recipient_ldap_profile Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group. Optional
recipient_email_address_group Recipient Email group (use fortimail-email-group-list to retrieve all the Email groups). Relevant when recipient_type=Email address group. Optional
antispam_profile The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles. Optional
antivirus_profile The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles. Optional
content_profile The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles. Optional
resource_profile The name of the resource profile that you want to apply to connections matching the policy. Use fortimail-resource-profile to retrieve all the resources. Required
auth_type The type of the authentication profile that this policy will apply. Possible values are: imap, ldap, pop3, radius, smpt. Optional
auth_profile The name of an authentication profile for the type. When auth_type is LDAP, insert LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. When auth_type is RADIUS, insert RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles. When auth_type is POP3, insert POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles. When auth_type is IMAP, insert IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles. When auth_type is SMTP, insert SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles. Relevant when auth_type is chosen. Optional
use_smtp_auth Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data. Possible values are: enable, disable. Default is disable. Optional
smtp_different Whether to reject different SMTP sender identity for authenticated user. Possible values are: enable, disable. Default is disable. Optional
smtp_diff_identity_ldap Whether to verify SMTP sender identity with LDAP for authenticated email. Possible values are: enable, disable. Default is disable. Optional
smtp_diff_identity_ldap_profile LDAP profile for SMTP sender identity verification. Optional
enable_pki Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password. Possible values are: enable, disable. Default is disable. Optional
pki_profile The name of a PKI user. Relevant when enable_pki is enable. Use fortimail-pki-user-list to retrieve all the PKI users. Optional
certificate_validation Whether to require valid certificates only and disallow password-style fallback. If the email user’s web browser does not provide a valid personal certificate, the FortiMail unit will fall back to standard user name and password-style authentication. Possible values are: enable, disable. Default is disable. Optional

Context Output

Path Type Description
FortiMail.RecipientPolicy.comment String A brief comment for the IP policy.
FortiMail.RecipientPolicy.mkey Number The ID of the recipient policy.
FortiMail.RecipientPolicy.direction String ‘The type of the recipient policy. 1: Inbound, 2: Outbound.’
FortiMail.RecipientPolicy.sender_type String ‘Define sender (MAIL FROM:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3: Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.sender_pattern String The local part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_domain String The domain part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_ldap_profile String Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.sender_email_address_group String The sender email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.sender_pattern_regex String The sender email address regular expression pattern.
FortiMail.RecipientPolicy.groupmode String ‘Define recipient (RCPT TO:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3: Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.recipient_pattern String The local part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.recipient_domain String The domain part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.ldap_profile String Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.recipient_email_address_group String The recipient email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.recipient_pattern_regex String The recipient email address regular expression pattern.
FortiMail.RecipientPolicy.antispam String The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles.
FortiMail.RecipientPolicy.content String The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles.
FortiMail.RecipientPolicy.profile_dlp String The name of the resource profile that you want to apply to connections matching the policy. Use fortimail-resource-profile to retrieve all the resources.
FortiMail.RecipientPolicy.antivirus String The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles.
FortiMail.RecipientPolicy.misc String The type of the authentication profile that this policy apply.
FortiMail.RecipientPolicy.auth String RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles.
FortiMail.RecipientPolicy.radius_auth String LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles.
FortiMail.RecipientPolicy.ldap_auth String POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles.
FortiMail.RecipientPolicy.pop3_auth String IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles.
FortiMail.RecipientPolicy.imap_auth String SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles.
FortiMail.RecipientPolicy.smtp_auth String Whether the policy allows email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiauth String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiuser String The name of a PKI user. Relevant when enable_pki is enable.
FortiMail.RecipientPolicy.auth_allow_smtp String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.RecipientPolicy.smtp_diff_identity String Whether to reject different SMTP sender identity for authenticated user.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.RecipientPolicy.certificate_required String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.

Command example

!fortimail-recipient-policy-create comment=TalTest1 resource_profile=Res_Default

Context Example

{
    "FortiMail": {
        "RecipientPolicy": {
            "antispam": "",
            "antivirus": "",
            "comment": "TalTest1",
            "content": "",
            "direction": "Inbound",
            "groupmode": 0,
            "imap_auth": "",
            "ldap_auth": "",
            "ldap_profile": "",
            "misc": "Res_Default",
            "mkey": 15,
            "pkiauth": "disable",
            "pkiuser": "",
            "pop3_auth": "",
            "profile_dlp": "",
            "profile_user_import_recipient": "",
            "profile_user_import_sender": "",
            "radius_auth": "",
            "recipient_domain": "*",
            "recipient_email_address_group": "",
            "recipient_import_attribute_name": "",
            "recipient_import_attribute_value": "",
            "recipient_pattern": "*",
            "recipient_pattern_regex": ".*",
            "sender_domain": "*",
            "sender_email_address_group": "",
            "sender_import_attribute_name": "",
            "sender_import_attribute_value": "",
            "sender_ldap_profile": "",
            "sender_pattern": "*",
            "sender_pattern_regex": ".*",
            "sender_type": "User (wildcard)",
            "smtp_auth": "",
            "smtp_diff_identity_ldap": "disable",
            "smtp_diff_identity_ldap_profile": "",
            "status": "enable"
        }
    }
}

Human Readable Output

Recipient Policy created successfully

Comment Direction Name PKI Auth Recipient Pattern Regex Resource Profile Sender Pattern Sender Type Status
TalTest1 Inbound 15 disable .* Res_Default * User (wildcard) enable

fortimail-recipient-policy-update


Update a recipient policy.

Base Command

fortimail-recipient-policy-update

Input

Argument Name Description Required
recipient_policy_id The ID of the recipient policy. Required
type The mail traffic direction. Possible values are: Inbound, Outbound. Optional
status Whether to apply the policy. Possible values are: enable, disable. Default is enable. Optional
comment A brief comment for the IP policy. Optional
sender_type Define sender (MAIL FROM:) email addresses that match this policy. If you enter LDAP group, also configure sender_ldap_profile by entering an LDAP profile in which you have enabled and configured a group query. If you enter Email address group, also configure sender_email_address_group by entering an Email group in which you have enabled and configured a group query. Possible values are: User (wildcard), User (regex), LDAP group, Email address group. Optional
sender_pattern The policy sender pattern. When sender_type is User (wildcard), insert email addresses that match this policy. For example, test@test.com. When sender_type is User (regex), insert the recipient email address regular expression pattern. When sender_type is LDAP group, insert the sender pattern. When sender_type is Email address group, insert email group (use fortimail-email-group-list to retrieve all the email groups). Optional
sender_ldap_profile Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when sender_type= LDAP Group. Optional
sender_email_address_group Sender Email group (use fortimail-email-group-list to retrieve all the Email groups). Relevant when recipient_type=Email address group. Optional
recipient_type Define recipient (RCPT TO:) email addresses that match this policy. If you enter LDAP group, also configure recipient_ldap_profile by entering an LDAP profile in which you have enabled and configured a group query. If you enter Email address group, also configure recipient_email_address_group by entering an Email group in which you have enabled and configured a group query. Possible values are: User (wildcard), User (regex), LDAP group, Email address group. Optional
recipient_pattern The policy recipient pattern. When recipient_type is User (wildcard), insert the local part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy and after insert @ and the domain part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy. For example, test@test.com. When recipient_type is User (regex), insert the recipient email address regular expression pattern. When recipient_type is LDAP group, insert the sender pattern. When recipient_type is Email address group, insert email group (use fortimail-email-group-list to retrieve all the email groups). Optional
recipient_ldap_profile Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group. Optional
recipient_email_address_group Recipient Email group (use fortimail-email-group-list to retrieve all the Email groups). Relevant when recipient_type=Email address group. Optional
antispam_profile The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles. Optional
antivirus_profile The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles. Optional
content_profile The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles. Optional
resource_profile The name of the resource profile that you want to apply to connections matching the policy. Use fortimail-resource-profile to retrieve all the resources. Optional
auth_type The type of the authentication profile that this policy will apply. Possible values are: imap, ldap, pop3, radius, smpt. Optional
auth_profile The name of an authentication profile for the type. When auth_type is LDAP, insert LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles. When auth_type is RADIUS, insert RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles. When auth_type is POP3, insert POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles. When auth_type is IMAP, insert IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles. When auth_type is SMTP, insert SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles. Relevant when auth_type is chosen. Optional
use_smtp_auth Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data. Possible values are: enable, disable. Optional
smtp_different Whether to reject different SMTP sender identity for authenticated user. Possible values are: enable, disable. Optional
smtp_diff_identity_ldap Whether to verify SMTP sender identity with LDAP for authenticated email. Possible values are: enable, disable. Optional
smtp_diff_identity_ldap_profile LDAP profile for SMTP sender identity verification. Optional
enable_pki Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password. Possible values are: enable, disable. Optional
pki_profile The name of a PKI user. Relevant when enable_pki is enable. Use fortimail-pki-user-list to retrieve all the PKI users. Optional
certificate_validation Whether to require valid certificates only and disallow password-style fallback. If the email user’s web browser does not provide a valid personal certificate, the FortiMail unit will fall back to standard user name and password-style authentication. Possible values are: enable, disable. Optional

Context Output

Path Type Description
FortiMail.RecipientPolicy.comment String A brief comment for the IP policy.
FortiMail.RecipientPolicy.mkey Number The ID of the recipient policy.
FortiMail.RecipientPolicy.direction String ‘The type of the recipient policy. 1: Inbound, 2: Outbound.’
FortiMail.RecipientPolicy.sender_type String ‘Define sender (MAIL FROM:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3:Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.sender_pattern String The local part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_domain String The domain part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_ldap_profile String Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.sender_email_address_group String The sender email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.sender_pattern_regex String The sender email address regular expression pattern.
FortiMail.RecipientPolicy.groupmode String ‘Define recipient (RCPT TO:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3:Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.recipient_pattern String The local part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.recipient_domain String The domain part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.ldap_profile String Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.recipient_email_address_group String The recipient email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.recipient_pattern_regex String The recipient email address regular expression pattern.
FortiMail.RecipientPolicy.antispam String The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles.
FortiMail.RecipientPolicy.content String The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles.
FortiMail.RecipientPolicy.profile_dlp String The name of the resource profile that you want to apply to connections matching the policy. Use fortimail-resource-profile to retrieve all the resources.
FortiMail.RecipientPolicy.antivirus String The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles.
FortiMail.RecipientPolicy.misc String The type of the authentication profile that this policy apply.
FortiMail.RecipientPolicy.auth String RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles.
FortiMail.RecipientPolicy.radius_auth String LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles.
FortiMail.RecipientPolicy.ldap_auth String POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles.
FortiMail.RecipientPolicy.pop3_auth String IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles.
FortiMail.RecipientPolicy.imap_auth String SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles.
FortiMail.RecipientPolicy.smtp_auth String Whether the policy allows email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiauth String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiuser String The name of a PKI user. Relevant when enable_pki is enable.
FortiMail.RecipientPolicy.auth_allow_smtp String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.RecipientPolicy.smtp_diff_identity String Whether to reject different SMTP sender identity for authenticated user.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.RecipientPolicy.certificate_required String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.

Command example

!fortimail-recipient-policy-update recipient_policy_id=1 comment=test2

Context Example

{
    "FortiMail": {
        "RecipientPolicy": {
            "comment": "test2",
            "mkey": 1,
            "status": "enable"
        }
    }
}

Human Readable Output

Recipient Policy updated successfully

Comment Name Status
test2 1 enable

fortimail-recipient-policy-delete


Delete a recipient policy.

Base Command

fortimail-recipient-policy-delete

Input

Argument Name Description Required
recipient_policy_id The ID of the recipient policy to be remove. Use fortimail-recipient-policy-list to retrieve all the recipient policies. Required

Context Output

There is no context output for this command.

Command example

!fortimail-recipient-policy-delete recipient_policy_id=14

Context Example

{
    "FortiMail": {
        "RecipientPolicy": {
            "mkey": "14"
        }
    }
}

Human Readable Output

Recipient Policy deleted successfully

fortimail-recipient-policy-move


Move a recipient policy location in the policy list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

Base Command

fortimail-recipient-policy-move

Input

Argument Name Description Required
recipient_policy_id The ID of the recipient policy to be moved. Use fortimail-recipient-policy-list to retrieve all the recipient policies. Required
reference_id The reference ID of the access control rule when moving before/after. Optional
action The move action. Possible values are: up, down, before, after. Optional

Context Output

There is no context output for this command.

Command example

!fortimail-recipient-policy-move recipient_policy_id=1 reference_id=5 action=after

Human Readable Output

Recipient Policy moved successfully

fortimail-recipient-policy-list


List recipient policies. If an ID is given, the command will return the information about the specified recipient policy.

Base Command

fortimail-recipient-policy-list

Input

Argument Name Description Required
recipient_policy_id The ID of the recipient policy. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.RecipientPolicy.comment String A brief comment for the IP policy.
FortiMail.RecipientPolicy.mkey Number The ID of the recipient policy.
FortiMail.RecipientPolicy.direction String ‘The type of the recipient policy. 1: Inbound, 2: Outbound.’
FortiMail.RecipientPolicy.sender_type String ‘Define sender (MAIL FROM:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3:Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.sender_pattern String The local part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_domain String The domain part of sender email address to define sender (MAIL FROM:) email addresses that match this policy.
FortiMail.RecipientPolicy.sender_ldap_profile String Sender LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.sender_email_address_group String The sender email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.sender_pattern_regex String The sender email address regular expression pattern.
FortiMail.RecipientPolicy.groupmode String ‘Define recipient (RCPT TO:) email addresses that match this policy. 0: User (wildcard), 2: LDAP group, 3:Email address group, 4: User(regex).’
FortiMail.RecipientPolicy.recipient_pattern String The local part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.recipient_domain String The domain part of recipient email address to define recipient (RCPT TO:) email addresses that match this policy.
FortiMail.RecipientPolicy.ldap_profile String Recipient LDAP profile (use fortimail-ldap-group-list to retrieve all the LDAP profiles). Relevant when recipient_type= LDAP Group.
FortiMail.RecipientPolicy.recipient_email_address_group String The recipient email group (use fortimail-email-group-list to retrieve all the email groups).
FortiMail.RecipientPolicy.recipient_pattern_regex String The recipient email address regular expression pattern.
FortiMail.RecipientPolicy.antispam String The name of an outgoing anti-spam profile, if any, that this policy will apply. Use fortimail-antispam-profile-list to retrieve all the anti-spam profiles.
FortiMail.RecipientPolicy.content String The name of the content profile that you want to apply to connections matching the policy. Use fortimail-content-profile-list to retrieve all the content profiles.
FortiMail.RecipientPolicy.profile_dlp String The name of the resource profile that you want to apply to connections matching the policy. Use fortimail-resource-profile to retrieve all the resources.
FortiMail.RecipientPolicy.antivirus String The name of an antivirus profile, if any, that this policy will apply. Use fortimail-antivirus-profile-list to retrieve all the antivirus profiles.
FortiMail.RecipientPolicy.misc String The type of the authentication profile that this policy apply.
FortiMail.RecipientPolicy.auth String RADIUS authentication profile. Use fortimail-radius-auth-profile to retrieve all the RADIUS authentication profiles.
FortiMail.RecipientPolicy.radius_auth String LDAP authentication profile. Use fortimail-ldap-group-list to retrieve all the LDAP authentication profiles.
FortiMail.RecipientPolicy.ldap_auth String POP3 authentication profile. Use fortimail-pop3-auth-profile to retrieve all the POP3 authentication profiles.
FortiMail.RecipientPolicy.pop3_auth String IMAP authentication profile. Use fortimail-imap-auth-profile to retrieve all the IMAP authentication profiles.
FortiMail.RecipientPolicy.imap_auth String SMTP authentication profile. Use fortimail-smtp-auth-profile to retrieve all the SMTP authentication profiles.
FortiMail.RecipientPolicy.smtp_auth String Whether the policy allows email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiauth String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.
FortiMail.RecipientPolicy.pkiuser String The name of a PKI user. Relevant when enable_pki is enable.
FortiMail.RecipientPolicy.auth_allow_smtp String Whether to authenticate SMTP connections using the authentication profile configured in sensitive-data.
FortiMail.RecipientPolicy.smtp_diff_identity String Whether to reject different SMTP sender identity for authenticated user.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap String Whether to verify SMTP sender identity with LDAP for authenticated email.
FortiMail.RecipientPolicy.smtp_diff_identity_ldap_profile String LDAP profile for SMTP sender identity verification.
FortiMail.RecipientPolicy.certificate_required String Whether to allow email users to log in to their per-recipient spam quarantine by presenting a certificate rather than a user name and password.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "RecipientPolicy": [
            {
                "antispam": "AS_Inbound@system",
                "antivirus": "AV_Discard@system",
                "comment": "",
                "content": "CF_Inbound@system",
                "direction": "Inbound",
                "groupmode": 4,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "test",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 5,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "new_version3242342.0@system",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "tal",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "User (regex)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 1,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "auth": "ldap",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 4,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 6,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "test",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "LDAP group",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 3,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Outbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "",
                "mkey": 4,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 7,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 3,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "tal",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 8,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "new_version3242342.0@system",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "new_version3242342.0@system",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "tal",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "Email address group",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 9,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 10,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 11,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Outbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "",
                "mkey": 12,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Outbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "",
                "mkey": 13,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "****@ron.com",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 2,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            },
            {
                "antispam": "",
                "antivirus": "",
                "comment": "",
                "content": "",
                "direction": "Inbound",
                "groupmode": 0,
                "imap_auth": "",
                "ldap_auth": "",
                "ldap_profile": "",
                "mdomain": "system",
                "misc": "Res_Default@system",
                "mkey": 15,
                "pkiauth": "disable",
                "pkiuser": "",
                "pop3_auth": "",
                "profile_dlp": "",
                "profile_user_import_recipient": "",
                "profile_user_import_sender": "",
                "radius_auth": "",
                "recipient_domain": "*",
                "recipient_email_address_group": "",
                "recipient_import_attribute_name": "",
                "recipient_import_attribute_value": "",
                "recipient_pattern": "*",
                "recipient_pattern_regex": ".*",
                "sender_domain": "*",
                "sender_email_address_group": "",
                "sender_import_attribute_name": "",
                "sender_import_attribute_value": "",
                "sender_ldap_profile": "",
                "sender_pattern": "*",
                "sender_pattern_regex": ".*",
                "sender_type": "User (wildcard)",
                "smtp_auth": "",
                "status": "enable"
            }
        ]
    }
}

Human Readable Output

Recipient Policy list

Name Status Sender Type Sender Pattern Recipient Pattern Regex anti-spam Content PKI Auth Direction Antivirus Resource Profile
5 enable User (regex) * .* AS_Inbound@system CF_Inbound@system disable Inbound AV_Discard@system Res_Default@system
1 enable User (wildcard) **@ron.com .*     disable Inbound   Res_Default@system
6 enable LDAP group * .*     disable Inbound   Res_Default@system
3 enable User (wildcard) * .*     disable Inbound   Res_Default@system
4 enable User (wildcard) * .*     disable Outbound    
7 enable User (wildcard) **@ron.com .*     disable Inbound   Res_Default@system
8 enable Email address group * .*     disable Inbound   Res_Default@system
9 enable User (wildcard) **@ron.com .*     disable Inbound   Res_Default@system
10 enable User (wildcard) **@ron.com .*     disable Inbound   Res_Default@system
11 enable User (wildcard) **@ron.com .*     disable Inbound   Res_Default@system
12 enable User (wildcard) **@ron.com .*     disable Outbound    
13 enable User (wildcard) **@ron.com .*     disable Outbound    
2 enable User (wildcard) * .*     disable Inbound   Res_Default@system
15 enable User (wildcard) * .*     disable Inbound   Res_Default@system

fortimail-tls-profile-list


List TLS profiles. TLS profiles allow you to selectively disable or enable TLS for specific email recipient patterns, IP subnets, and so on. A common use of TLS profiles is to enforce TLS transport to a specific domain and verify the certificate of the receiving servers. If a name is given, the command will return the information about the specified TLS profile. Mainly used in the configuration of access control rule.

Base Command

fortimail-tls-profile-list

Input

Argument Name Description Required
name The name of the TLS profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.TLSprofile.mkey String The name of the TLS profile.
FortiMail.TLSprofile.level Number The TLS level.
FortiMail.TLSprofile.action String The TLS action on failure.
FortiMail.TLSprofile.comment String A brief comment for the TLS profile.
FortiMail.TLSprofile.is_referenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "TLSprofile": [
            {
                "action": true,
                "comment": "tal",
                "level": 2,
                "mkey": "tal"
            },
            {
                "action": false,
                "comment": "test",
                "level": 4,
                "mkey": "test"
            }
        ]
    }
}

Human Readable Output

Tls Profile list

Name Comment TLS level Action On Failure Action
tal tal 2 true true
test test 4 false false

fortimail-ldap-group-list


List LDAP profiles. LDAP groups lets to allow match email addresses as sender or recipients with the LDAP profile authentication in the access control rule configuration and is the authentication profile in case the authentication type in IP policy is LDAP. If a name is given, the command will return the information about the specified LDAP profile. Mainly used in the configuration of access control rule and the IP policy.

Base Command

fortimail-ldap-group-list

Input

Argument Name Description Required
name The name of the anti-spam LDAP profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.LDAPprofile.mkey String The name of the LDAP profile.
FortiMail.LDAPprofile.server Number The LDAP profile server.
FortiMail.LDAPprofile.port String The LDAP profile port.
FortiMail.LDAPprofile.comment String A brief comment for the LDAP group.
FortiMail.LDAPprofile.is_referenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "LDAPprofile": [
            {
                "access_override": false,
                "access_override_attribute": "",
                "address_map_state": false,
                "alias_state": true,
                "asav_state": false,
                "authstate": true,
                "cache_state": true,
                "comment": "",
                "domain_lookup_enable": false,
                "domain_override": false,
                "domain_override_attribute": "",
                "groupstate": false,
                "isReferenced": 2,
                "mkey": "tal",
                "port": 389,
                "result": "",
                "routing_state": false,
                "separate_bind_alias": false,
                "server": "2.2.2.2",
                "webmailstatus": false
            },
            {
                "access_override": false,
                "access_override_attribute": "",
                "address_map_state": false,
                "alias_state": true,
                "asav_state": false,
                "authstate": true,
                "cache_state": true,
                "comment": "",
                "domain_lookup_enable": false,
                "domain_override": false,
                "domain_override_attribute": "",
                "groupstate": false,
                "isReferenced": 12,
                "mkey": "test",
                "port": 389,
                "result": "",
                "routing_state": false,
                "separate_bind_alias": false,
                "server": "",
                "webmailstatus": false
            }
        ]
    }
}

Human Readable Output

Ldap Group list

Name Server Port Group State Auth State Alias State Routing State Address Map State Cache State
tal 2.2.2.2 389 false true true false false true
test   389 false true true false false true

fortimail-geoip-group-list


List GeoIP groups. FortiMail utilizes the GeoIP database to map the geo locations of client IP addresses. You can use GeoIP groups in access control rules and IP-based policies to geo-targeting spam and virus devices. If a name is given, the command will return the information about the specified GeoIP profile. Mainly used in the configuration of access control rule and the IP policy.

Base Command

fortimail-geoip-group-list

Input

Argument Name Description Required
name The name of the anti-spam GeoIP group. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.GeoIPgroup.mkey String The name of the GeoIP group.
FortiMail.GeoIPgroup.country Number A list of the GeoIP group countries.
FortiMail.GeoIPgroup.comment String A brief comment for the GeoIP group countries.
FortiMail.GeoIPgroup.is_referenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "GeoIPgroup": [
            {
                "comment": "",
                "country": "AO,AR,AW,AT,BF,CM,CV,KY,CF",
                "isReferenced": 1,
                "mkey": "Test_3"
            },
            {
                "comment": "",
                "country": "",
                "mkey": "test_2"
            },
            {
                "comment": "test",
                "country": "AL,DZ,AD,AQ",
                "mkey": "test_ben"
            }
        ]
    }
}

Human Readable Output

Geoip Group list

Name Comment Country
Test_3   AO,AR,AW,AT,BF,CM,CV,KY,CF
test_2    
test_ben test AL,DZ,AD,AQ

fortimail-antispam-profile-list


List AntiSpam profiles. Antispam profiles are sets of antispam scans that you can apply by selecting one in a policy. If a name is given, the command will return the information about the specified AntiSpam profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-antispam-profile-list

Input

Argument Name Description Required
name The name of the anti-spam profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.AntispamProfile.mkey String The name of the anti-spam profile.
FortiMail.AntispamProfile.dictionary_type Number The type of the dictionary type.
FortiMail.AntispamProfile.minimum_dictionary_score Number The minimum number of the dictionary score.
FortiMail.AntispamProfile.comment String A brief comment for the anti-spam profile.
FortiMail.AntispamProfile.isReferenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "AntispamProfile": [
            {
                "comment": "",
                "dictionary_type": 1,
                "isReferenced": 1,
                "minimum_dictionary_score": 1,
                "mkey": "AS_Inbound"
            },
            {
                "comment": "",
                "dictionary_type": 1,
                "minimum_dictionary_score": 1,
                "mkey": "AS_Inbound_High"
            },
            {
                "comment": "",
                "dictionary_type": 1,
                "minimum_dictionary_score": 1,
                "mkey": "AS_Outbound"
            },
            {
                "comment": "fortimail-antispam-profile-listfortimail-antispam-profile-listfortimail-antispam-profile-list",
                "dictionary_type": 1,
                "minimum_dictionary_score": 1,
                "mkey": "fortimail-antispam-profile-list"
            }
        ]
    }
}

Human Readable Output

Antispam Profile list

Name Comment
AS_Inbound  
AS_Inbound_High  
AS_Outbound  
fortimail-antispam-profile-list fortimail-antispam-profile-listfortimail-antispam-profile-listfortimail-antispam-profile-list

fortimail-antivirus-profile-list


List AntiVirus profiles. if the FortiMail unit detects a virus, it will take actions as you define in the antivirus action profiles. If a name is given, the command will return the information about the specified AntiVirus profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-antivirus-profile-list

Input

Argument Name Description Required
name The name of the antivirus profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.AntivirusProfile.mkey String The name of the antivirus profile.
FortiMail.AntivirusProfile.comment String A brief comment for the antivirus profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "AntivirusProfile": [
            {
                "comment": "",
                "isReferenced": 1,
                "mkey": "AV_Discard"
            },
            {
                "comment": "",
                "mkey": "AV_Reject"
            },
            {
                "comment": "",
                "mkey": "AV_SysQuarantine"
            },
            {
                "comment": "fortimail-antivirus-profile-list",
                "mkey": "fortimail-antivirus-profile-list"
            }
        ]
    }
}

Human Readable Output

Antivirus Profile list

Name Comment
AV_Discard  
AV_Reject  
AV_SysQuarantine  
fortimail-antivirus-profile-list fortimail-antivirus-profile-list

fortimail-content-profile-list


List Content profiles. Content profiles enable matching emails based upon its subject line, message body, and attachments. If a name is given, the command will return the information about the specified content profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-content-profile-list

Input

Argument Name Description Required
name The name of the content profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.ContentProfile.mkey String The name of the content profile.
FortiMail.ContentProfile.comment String A brief comment for the content profile.
FortiMail.ContentProfile.isReferenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "ContentProfile": [
            {
                "comment": "",
                "isReferenced": 1,
                "mkey": "CF_Inbound"
            },
            {
                "comment": "",
                "mkey": "CF_Outbound"
            },
            {
                "comment": "fortimail-content-profile-list",
                "mkey": "fortimail-content-profile-list"
            }
        ]
    }
}

Human Readable Output

Content Profile list

Name Comment
CF_Inbound  
CF_Outbound  
fortimail-content-profile-list fortimail-content-profile-list

fortimail-ip-pool-list


List IP pool profiles. IP pools define a range of IP addresses, and can be used in multiple ways: To define source IP addresses used by the FortiMail unit if you want outgoing email to originate from a range of IP addresses. To define destination addresses used by the FortiMail unit if you want incoming email to destine to the virtual host on a range of IP addresses. If a name is given, the command will return the information about the specified IP pool. Mainly used in the configuration of IP policy.

Base Command

fortimail-ip-pool-list

Input

Argument Name Description Required
name The name of the IP pool. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.IPPool.mkey String The name of the IP pool.
FortiMail.IPPool.ip_range Number The IP pool IP group.
FortiMail.IPPool.smtp_certificate String The SMTP certificate.
FortiMail.IPPool.smtp_certificate_direction String The SMTP certificate direction.
FortiMail.IPPool.smtp_greeting_reply_name Number The SMTP greeting name.
FortiMail.IPPool.comment String A brief comment for the anti-spam profile.
FortiMail.IPPool.is_certificate_expired Boolean Whether the certificate expired.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "IPPool": [
            {
                "comment": "fortimail-ip-pool-list",
                "ip_range": "test1",
                "is_certificate_expired": false,
                "mkey": "fortimail-ip-pool-list",
                "smtp_certificate": "Factory",
                "smtp_certificate_direction": 3,
                "smtp_greeting_reply_name": "fortimail-ip-pool-list"
            },
            {
                "comment": "",
                "ip_range": "test",
                "is_certificate_expired": false,
                "mkey": "tal-pool",
                "smtp_certificate": "",
                "smtp_certificate_direction": 2,
                "smtp_greeting_reply_name": ""
            },
            {
                "comment": "tal test",
                "ip_range": "test1",
                "is_certificate_expired": false,
                "mkey": "test_tal",
                "smtp_certificate": "Self",
                "smtp_certificate_direction": 3,
                "smtp_greeting_reply_name": ""
            }
        ]
    }
}

Human Readable Output

Ip Pool list

Name Comment IP Group SMTP Certificate SMTP Certificate Direction SMTP Greeting Name
fortimail-ip-pool-list fortimail-ip-pool-list test1 Factory 3 fortimail-ip-pool-list
tal-pool   test   2  
test_tal tal test test1 Self 3  

fortimail-session-profile-list


List IP session profiles. Session profiles focus on the connection and envelope portion of the SMTP session. If a name is given, the command will return the information about the specified session profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-session-profile-list

Input

Argument Name Description Required
name The name of the session profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.SessionProfile.mkey String The name of the session profile.
FortiMail.SessionProfile.comment String A brief comment for the anti-spam profile.
FortiMail.SessionProfile.action Boolean The action of the session profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "SessionProfile": [
            {
                "action": "",
                "comment": "fortimail-session-profile-list",
                "mkey": "Inbound_Session"
            },
            {
                "action": "",
                "comment": "",
                "mkey": "Outbound_Session"
            }
        ]
    }
}

Human Readable Output

Session Profile list

Name Comment
Inbound_Session fortimail-session-profile-list
Outbound_Session  

fortimail-radius-auth-profile-list


List RADIUS authentication profiles. If a name is given, the command will return the information about the specified RADIUS authentication profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-radius-auth-profile-list

Input

Argument Name Description Required
name The name of the RADIUS auth profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.RadiusAuthProfile.mkey String The name of the RADIUS authentication profile.
FortiMail.RadiusAuthProfile.comment String A brief comment for the RADIUS authentication profile.
FortiMail.RadiusAuthProfile.server Boolean The server name of the RADIUS authentication profile.
FortiMail.RadiusAuthProfile.authport Number The server port of the RADIUS authentication profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "RadiusAuthProfile": {
            "access_override_vendor": 12356,
            "access_profile_override": true,
            "access_profile_override_attribute": 6,
            "authport": 1812,
            "comment": "fortimail-radius-auth-profile-list",
            "domain_override": true,
            "domain_override_attribute": 3,
            "domain_override_vendor": 12356,
            "mkey": "fortimail-radius-auth-profile-list",
            "server": "127.0.0.1"
        }
    }
}

Human Readable Output

Radius Auth Profile list

Name Comment Server Auth Port Access Override Vendor Domain Override Vendor
fortimail-radius-auth-profile-list fortimail-radius-auth-profile-list 127.0.0.1 1812 12356 12356

fortimail-pop3-auth-profile-list


List POP3 authentication profiles. If a name is given, the command will return the information about the specified POP3 authentication profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-pop3-auth-profile-list

Input

Argument Name Description Required
name The name of the POP3 auth profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.Pop3AuthProfile.mkey String The name of the POP3 authentication profile.
FortiMail.Pop3AuthProfile.comment String A brief comment for the POP3 authentication profile.
FortiMail.Pop3AuthProfile.server Boolean The server name of the POP3 authentication profile.
FortiMail.Pop3AuthProfile.port Number The port of the POP3 authentication profile.
FortiMail.Pop3AuthProfile.auth_type Number The authentication type of the POP3 authentication profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "Pop3AuthProfile": {
            "auth_type": 0,
            "comment": "fortimail-radius-auth-profile-list",
            "mkey": "fortimail-radius-auth-profile-listpop",
            "port": 110,
            "server": "1.1.1.1"
        }
    }
}

Human Readable Output

Pop3 Auth Profile list

Name Comment Server Auth Type Port
fortimail-radius-auth-profile-listpop fortimail-radius-auth-profile-list 1.1.1.1 0 110

fortimail-imap-auth-profile-list


List IMAP authentication profiles. If a name is given, the command will return the information about the specified IMAP authentication profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-imap-auth-profile-list

Input

Argument Name Description Required
name The name of the IMAP auth profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.ImapAuthProfile.mkey String The name of the IMAP authentication profile.
FortiMail.ImapAuthProfile.comment String A brief comment for the IMAP authentication profile.
FortiMail.ImapAuthProfile.server Boolean The server name of the IMAP authentication profile.
FortiMail.ImapAuthProfile.port Number The port of the IMAP authentication profile.
FortiMail.ImapAuthProfile.auth_type Number The authentication type of the IMAP authentication profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "ImapAuthProfile": {
            "auth_type": 3,
            "comment": "fortimail-radius-auth-profile-list",
            "mkey": "fortimail-radius-auth-profile-listimap",
            "port": 143,
            "server": "2.2.2.2"
        }
    }
}

Human Readable Output

Imap Auth Profile list

Name Comment Server Auth Type Port
fortimail-radius-auth-profile-listimap fortimail-radius-auth-profile-list 2.2.2.2 3 143

fortimail-smtp-auth-profile-list


List SMTP authentication profiles. If a name is given, the command will return the information about the specified SMTP authentication profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-smtp-auth-profile-list

Input

Argument Name Description Required
name The name of the SMTP auth profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.SmtpAuthProfile.mkey String The name of the SMTP authentication profile.
FortiMail.SmtpAuthProfile.comment String A brief comment for the SMTP authentication profile.
FortiMail.SmtpAuthProfile.server Boolean The server name of the SMTP authentication profile.
FortiMail.SmtpAuthProfile.port Number The port of the SMTP authentication profile.
FortiMail.SmtpAuthProfile.auth_type Number The authentication type of the SMTP authentication profile.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "SmtpAuthProfile": {
            "auth_type": 1,
            "comment": "fortimail-radius-auth-profile-list",
            "mkey": "fortimail-radius-auth-profile-listsmtp",
            "port": 25,
            "server": "3.3.3.3"
        }
    }
}

Human Readable Output

Smtp Auth Profile list

Name Comment Server Auth Type Port
fortimail-radius-auth-profile-listsmtp fortimail-radius-auth-profile-list 3.3.3.3 1 25

fortimail-resource-profile-list


List resource profiles. Resouce profile configure miscellaneous aspects of the email user accounts, such as disk space quota. If a name is given, the command will return the information about the specified resource profile. Mainly used in the configuration of IP policy.

Base Command

fortimail-resource-profile-list

Input

Argument Name Description Required
name The name of the resource profile. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.ResourceProfile.mkey String The name of the resource profile.
FortiMail.ResourceProfile.comment String A brief comment for the resource profile.
FortiMail.ResourceProfile.is_referenced Number Number of referencing entities.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "ResourceProfile": {
            "comment": "",
            "isReferenced": 11,
            "mkey": "Res_Default"
        }
    }
}

Human Readable Output

Resource Profile list

Name
Res_Default

fortimail-pki-user-list


List PKI users. PKI users can authenticate by presenting a valid client certificate, rather than by entering a username and password. If a name is given, the command will return the information about the specified PKI user. Mainly used in the configuration of recipient policy.

Base Command

fortimail-pki-user-list

Input

Argument Name Description Required
name The name of the PKI user. Optional
all_results Whether to retrieve all results by overriding the default limit. Possible values are: true, false. Default is false. Optional
limit The maximum number of records to retrieve. Default is 50. Optional

Context Output

Path Type Description
FortiMail.PKIuser.mkey String The name of the PKI user.
FortiMail.PKIuser.domain String The domain of the PKI user.
FortiMail.PKIuser.subject Number The subject of the PKI user.
FortiMail.PKIuser.ldapprofile String The LDAP profile of the PKI user.

Command example


#### Context Example

```json
{
    "FortiMail": {
        "PKIuser": [
            {
                "ca_certificate": "",
                "domain": "",
                "ldapfield": 0,
                "ldapprofile": "",
                "ldapquery": true,
                "mkey": "lior",
                "ocspaction": 1,
                "ocspca": "",
                "ocspurl": "",
                "ocspverify": false,
                "subject": "tola"
            },
            {
                "ca_certificate": "",
                "domain": "",
                "ldapfield": 0,
                "ldapprofile": "tal",
                "ldapquery": true,
                "mkey": "tal",
                "ocspaction": 1,
                "ocspca": "",
                "ocspurl": "",
                "ocspverify": false,
                "subject": ""
            }
        ]
    }
}

Human Readable Output

Pki User list

Name Subject LDAP Profile LDAP Query OCSP verify
lior tola   true false
tal   tal true false

Configuration parameters

  • url — Server URL (required)
  • credentials — Account username (required)
  • proxy — Use system proxy settings
  • insecure — Trust any certificate (not secure)

Commands (48)

  • fortimail-access-control-create

    Create an Access control rule. Access control rules take effect after the FortiMail unit has initiated or received an IP and TCP-level connection at the application layer of the network.

  • fortimail-access-control-delete

    Delete an access control rule.

  • fortimail-access-control-list

    List access control rules. If an ID is given, the command will return the information about the specific access control rule.

  • fortimail-access-control-move

    Move an access control rule location in the rules list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

  • fortimail-access-control-update

    Update an access control.

  • fortimail-antispam-profile-list

    List AntiSpam profiles. Antispam profiles are sets of anti-spam scans that you can apply by selecting one in a policy. If a name is given, the command will return the information about the specified AntiSpam profile. Mainly used in the configuration of IP policy..

  • fortimail-antivirus-profile-list

    List AntiVirus profiles. If the FortiMail unit detects a virus, it will take actions defined in the antivirus action profiles. If a name is given, the command will return the information about the specified AntiVirus profile. Mainly used in the configuration of IP policy.

  • fortimail-content-profile-list

    List content profiles. Content profiles enable matching emails based upon its subject line, message body, and attachments. If a name is given, the command will return the information about the specified content profile. Mainly used in the configuration of IP policy.

  • fortimail-email-group-create

    Create an email group. An email group is a container for a list of email addresses, allowing you to use it in configuring access control rules (for defining the sender and recipient matching) and recipient-based policies (for defining MAIL FROM addresses matching specific policies).

  • fortimail-email-group-delete

    Delete an email group.

  • fortimail-email-group-list

    List email groups. If a name is given, the command will return the information about the specified email group.

  • fortimail-email-group-member-add

    Add an email group member (email address) to an email group.

  • fortimail-email-group-member-delete

    Delete an email group member from an email group.

  • fortimail-email-group-member-list

    List email group members. If an email is given, the command will return the information about the specified email group member.

  • fortimail-email-group-member-replace

    Replace email group members with new members. This command overwrites all the email group members that were defined in the email group.

  • fortimail-email-group-update

    Update the comment of an email group.

  • fortimail-geoip-group-list

    List GeoIP groups. FortiMail utilizes the GeoIP database to map the geo locations of client IP addresses. You can use GeoIP groups in access control rules and IP-based policies to geo-targeting spam and virus devices. If a name is given, the command will return the information about the specified GeoIP profile. Mainly used in the configuration of access control rule and the IP policy.

  • fortimail-imap-auth-profile-list

    List IMAP authentication profiles. If a name is given, the command will return the information about the specified IMAP authentication profile. Mainly used in the configuration of IP policy.

  • fortimail-ip-group-create

    Create an IP group. IP group is a container that contains members of IP addresses that can be used when configuring access control rules (define the source IP group of the SMTP client attempting to send the email message) and IP-based policies (define the IP group of the SMTP source/destination to which the policy applies).

  • fortimail-ip-group-delete

    Delete an IP group.

  • fortimail-ip-group-list

    List IP groups. If a name is given, the command will return the information about the specified IP group.

  • fortimail-ip-group-member-add

    Add an IP group member (IP/Netmask or IP range) to an IP group. An IP group member is an IP address that can be used when configuring access control rules (define the source IP group of the SMTP client attempting to send the email message) and IP-based policies (define the IP group of the SMTP source/destination to which the policy applies).

  • fortimail-ip-group-member-delete

    Delete an IP group member from IP group.

  • fortimail-ip-group-member-list

    List IP group members. If an IP is given, the command will return the information about the specified IP group member.

  • fortimail-ip-group-member-replace

    Replace IP group members with new members. This command overwrites all the IP group members that were defined in the IP group.

  • fortimail-ip-group-update

    Update the comment of an IP group.

  • fortimail-ip-policy-create

    Create an IP policy. IP-based policies lets you control emails based on IP/Netmask / IP Group/ GeoIP Group/ ISDB.

  • fortimail-ip-policy-delete

    Delete an IP policy.

  • fortimail-ip-policy-list

    List an IP policy. If an ID is given, the command will return the information about the specified IP policy.

  • fortimail-ip-policy-move

    Move an IP policy location in the policy list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

  • fortimail-ip-policy-update

    Update an IP policy.

  • fortimail-ip-pool-list

    List IP pool profiles. IP pools define a range of IP addresses, and can be used in multiple ways: To define source IP addresses used by the FortiMail unit if you want outgoing email to originate from a range of IP addresses. To define destination addresses used by the FortiMail unit if you want incoming email to destine to the virtual host on a range of IP addresses. If a name is given, the command will return the information about the specified IP pool. Mainly used in the configuration of IP policy.

  • fortimail-ldap-group-list

    List LDAP profiles. LDAP groups enables matching email addresses as senders or recipients with the LDAP profile authentication in the access control rule configuration and is the authentication profile in case the authentication type in IP policy is LDAP. If a name is given, the command will return the information about the specified LDAP profile. Mainly used in the configuration of access control rule and the IP policy.

  • fortimail-pki-user-list

    List PKI users. PKI users can authenticate by presenting a valid client certificate, rather than by entering a username and password. If a name is given, the command will return the information about the specified PKI user. Mainly used in the configuration of recipient policy.

  • fortimail-pop3-auth-profile-list

    List POP3 authentication profiles. If a name is given, the command will return the information about the specified POP3 authentication profile. Mainly used in the configuration of IP policy.

  • fortimail-radius-auth-profile-list

    List RADIUS authentication profiles. If a name is given, the command will return the information about the specified RADIUS authentication profile. Mainly used in the configuration of IP policy.

  • fortimail-recipient-policy-create

    Create an Inbound/ Outbound Recipient policy. Recipient policies control email based on sender and recipient addresses. Recipient-based policies have precedence if an IP-based policy is also applicable but conflicts.

  • fortimail-recipient-policy-delete

    Delete a recipient policy.

  • fortimail-recipient-policy-list

    List recipient policies. If an ID is given, the command will return the information about the specified recipient policy.

  • fortimail-recipient-policy-move

    Move a recipient policy location in the policy list. FortiMail units match the policies in sequence, from the top of the list downwards. Therefore, you must put the more specific policies on top of the more generic ones.

  • fortimail-recipient-policy-update

    Update a recipient policy.

  • fortimail-resource-profile-list

    List resource profiles. Resource profile configure miscellaneous aspects of the email user accounts, such as disk space quota. If a name is given, the command will return the information about the specified resource profile. Mainly used in the configuration of IP policy.

  • fortimail-session-profile-list

    List IP session profiles. Session profiles focus on the connection and envelope portion of the SMTP session. If a name is given, the command will return the information about the specified session profile. Mainly used in the configuration of IP policy.

  • fortimail-smtp-auth-profile-list

    List SMTP authentication profiles. If a name is given, the command will return the information about the specified SMTP authentication profile. Mainly used in the configuration of IP policy.

  • fortimail-system-safe-block-add

    Add an email address/ domain name/ IP address to the system safe/block list. Block/safe list lets you reject, discard, or allow email messages based on email addresses, domain names, and IP addresses. As one of the first steps to detect spam, FortiMail units evaluate whether an email message matches a block list or safe list entry. Choose the required list by the type argument.

  • fortimail-system-safe-block-delete

    Delete an email address/ domain name/ IP address from the system safe/block list. Choose the required list by the type argument.

  • fortimail-system-safe-block-list

    List the system Block/Safe list. Choose the required list by the type argument.

  • fortimail-tls-profile-list

    List TLS profiles. TLS profiles allow you to selectively disable or enable TLS for specific email recipient patterns, IP subnets, and so on. A common use of TLS profiles is to enforce TLS transport to a specific domain and verify the certificate of the receiving servers. If a name is given, the command will return the information about the specified TLS profile. Mainly used in the configuration of access control rule.

import copy
import http
from functools import wraps
from collections.abc import Callable

import demistomock as demisto  # noqa: F401
import requests.utils
import urllib3
from CommonServerPython import *

urllib3.disable_warnings()

DEFAULT_COOKIE = {"cookie_name": None, "cookie_value": None}
AUTHORIZATION_ERROR = (
    "Authorization Error: invalid username or password or too many login attempts."
    "Please check credentials or wait and try again."
)
RP_DIRECTION_MAPPER = {"Inbound": 1, "Outbound": 2}
BOOLEAN_MAPPER = {"enable": True, "disable": False}
RP_AUTH_MAPPER = {"radius": 1, "ldap": 2, "pop3": 3, "imap": 4, "samtp": 5}
RP_PATTERN_TYPE_MAPPER = {
    "User (wildcard)": 0,
    "User (regex)": 4,
    "Email address group": 3,
    "LDAP group": 2,
}
AC_PATTERN_TYPE_MAPPER = {
    "External": 5,
    "Internal": 4,
    "Email Group": 2,
    "LDAP Group": 3,
    "LDAP Verification": 6,
    "Regular Expression": 1,
    "User Defined": 0,
}
AC_AUTH_MAPPER = {
    "Any": 0,
    "Not Authenticated": 2,
    "Authenticated": 1,
}
AC_SENDER_IP_TYPE_MAPPER = {
    "IP/Netmask": 0,
    "IP Group": 1,
    "GeoIP Group": 2,
    "ISDB": 3,
}
AC_ACTION_MAPPER = {
    "Safe & Relay": 1,
    "Safe": 5,
    "Relay": 2,
    "Receive": 6,
    "Reject": 3,
    "Discard": 4,
}
IP_ACTION_MAPPER = {
    "Scan": 0,
    "Fail Temporarily": 2,
    "Reject": 1,
    "Proxy bypass": 4,
}
DESTINATION_MAPPER = {
    "IP/Netmask": 1,
    "IP Group": 2,
}
OUTPUT_PREFIX_MAPPER = {
    "antispam_profile": "AntispamProfile",
    "geoip_group": "GeoIPgroup",
    "tls_profile": "TLSprofile",
    "ip_group": "IPGroup",
    "ip_group_member": "IPGroup",
    "email_group": "EmailGroup",
    "email_group_member": "EmailGroup",
    "system_safe_block": "SystemList",
    "ip_policy": "IPPolicy",
    "access_control": "AccessControl",
    "recipient_policy": "RecipientPolicy",
    "ldap_group": "LDAPprofile",
    "antivirus_profile": "AntivirusProfile",
    "content_profile": "ContentProfile",
    "ip_pool": "IPPool",
    "session_profile": "SessionProfile",
    "radius_auth_profile": "RadiusAuthProfile",
    "pop3_auth_profile": "Pop3AuthProfile",
    "imap_auth_profile": "ImapAuthProfile",
    "smtp_auth_profile": "SmtpAuthProfile",
    "resource_profile": "ResourceProfile",
    "pki_user": "PKIuser",
}
MOVE_ACTION = "14"
REPLACE_ACTION = "10"


def validate_authentication(func: Callable) -> Callable:
    """
    Decorator to manage authentication for API requests.
    This decorator first tries to execute the provided function using an existing authentication cookie
    stored in the 'integration_context'.
    If no valid cookie is available, or if the existing cookie is no longer valid (indicated by an
    HTTP FORBIDDEN status), it attempts to re-authenticate with the API and then re-execute the function.
    The 'integration_context' is used to store and retrieve the authentication cookie,
    allowing the decorator to use the latest valid authentication details across different executions.

    Args:
        func (Callable): The API request function to be executed.

    Raises:
        DemistoException:
            - If the API returns an HTTP FORBIDDEN status during the initial request
                attempt and re-authentication also fails.
            - If the API returns any other error during the request.

    Returns:
        Callable: The result from executing 'func' with the provided arguments and keyword arguments.
    """

    @wraps(wrapped=func)
    def wrapper(client: "Client", *args, **kwargs):
        def try_request():
            """
            Attempts to execute the API request function.
            If a 'FORBIDDEN' HTTP status code is encountered, indicating an authentication issue,
            it triggers a re-authentication and retries the request.
            """
            try:
                return func(client, *args, **kwargs)
            except DemistoException as exc:
                if exc.res is not None and exc.res.status_code == http.HTTPStatus.FORBIDDEN:
                    update_cookie()
                    return func(client, *args, **kwargs)
                set_integration_context(DEFAULT_COOKIE)
                raise

        def try_authentication():
            """
            Attempts to authenticate with the API and extract the cookie from the session.
            In case of a 'FORBIDDEN' status code or other exceptions, it handles them appropriately,
            updating the integration context or raising a tailored exception.
            """
            try:
                client.authentication()
                for cookie in client._session.cookies:
                    if cookie.name.startswith("APSCOOKIE"):
                        return cookie.name, cookie.value
                raise DemistoException("Authentication failed: cookie not found.")
            except DemistoException as exc:
                set_integration_context(DEFAULT_COOKIE)
                if exc.res is not None and exc.res.status_code == http.HTTPStatus.FORBIDDEN:
                    raise DemistoException(AUTHORIZATION_ERROR)
                raise

        def update_cookie():
            """Updates the session and integration context with a new cookie."""
            cookie_name, cookie_value = try_authentication()
            cookie = requests.utils.cookiejar_from_dict({cookie_name: cookie_value})
            client._session.cookies.update(cookie)
            set_integration_context({"cookie_name": cookie_name, "cookie_value": cookie_value})

        integration_context = get_integration_context()
        if (
            integration_context
            and (cookie_name := integration_context.get("cookie_name"))
            and (cookie_value := integration_context.get("cookie_value"))
        ):
            instance_cookie = {cookie_name: cookie_value}
            cookie = requests.utils.cookiejar_from_dict(instance_cookie)
            client._session.cookies.update(cookie)
            return try_request()
        # could happen on first run or if previous cookie setup failed or if previous cookie is expired
        update_cookie()
        return func(client, *args, **kwargs)

    return wrapper


class Client(BaseClient):
    def __init__(
        self,
        server_url: str,
        user_name: str,
        password: str,
        verify: bool = True,
        proxy: bool = False,
    ):
        self._base_url = server_url
        self.user_name = user_name
        self.password = password
        super().__init__(base_url=server_url, verify=verify, proxy=proxy)

    def authentication(self) -> None:
        """
        Login to FortiMail API.
        """
        self._session.cookies.clear()
        self._http_request(
            method="POST",
            url_suffix="api/v1/AdminLogin/",
            json_data={"name": self.user_name, "password": self.password},
        )

    @validate_authentication
    def create_ip_group(
        self,
        name: str,
        comment: str = None,
    ) -> Dict[str, Any]:
        """
        Create an IP group. IP group is a container that contains members of IP addresses that can be used
        when configuring access control rules (define the source IP group of the SMTP client attempting to
        send the email message) and IP-based policies (define the IP group of the SMTP source/destination
        to which the policy applies).

        Args:
            name (str): The name of the IP group. The name must contain only alphanumeric characters.
                Spaces are not allowed.
            comment (str | None): A brief comment for the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            f"api/v1/ProfIp_address_group/{name}/",
            json_data=remove_empty_elements({"comment": comment}),
        )

    @validate_authentication
    def update_ip_group(
        self,
        name: str,
        comment: str,
    ) -> Dict[str, Any]:
        """
        Update the comment of an IP group.

        Args:
            name (str): The name of the IP group to update.
            comment (str): A brief comment for the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "PUT",
            f"api/v1/ProfIp_address_group/{name}/",
            json_data={"comment": comment},
        )

    @validate_authentication
    def delete_ip_group(self, name: str) -> Dict[str, Any]:
        """
        Delete an IP group.

        Args:
            name (str | None): The name of the IP group to remove.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request("DELETE", f"api/v1/ProfIp_address_group/{name}")

    @validate_authentication
    def list_ip_group(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List IP groups. if a name is given, return the information about the specify IP group.

        Args:

            name (str, optional): The name of the IP group to retrieve. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            "GET",
            f"api/v1/ProfIp_address_group{url_suffix}",
        )

    @validate_authentication
    def add_ip_group_member(self, group_name: str, ip: str) -> Dict[str, Any]:
        """
        Add an IP group member (IP/Netmask or IP range) to IP group.
        IP group member is an IP addresses that can be used when configuring access control rules
        (define the source IP group of the SMTP client attempting to send the email message) and IP-based policies
        (define the IP group of the SMTP source/destination to which the policy applies).

        Args:
            group_name (str): The name of the IP group.
            ip (str): The IP address and net-mask to include in the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            f"api/v1/ProfIp_address_group/{group_name}/ProfIp_address_groupIpAddressGroupMember/{ip}",
        )

    @validate_authentication
    def replace_ip_group_member(
        self,
        group_name: str,
        ips: dict[str, str],
    ) -> Dict[str, Any]:
        """
        Replace IP group members with new members.
        This overwrites all the IP group members that defined in the IP group.

        Args:
            group_name (str): The name of the IP group.
            ips (dict[str, str]): A list of IP address (separated with a comma) to replace in the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            f"api/v1/ProfIp_address_group/{group_name}/ProfIp_address_groupIpAddressGroupMember",
            json_data={"reqAction": REPLACE_ACTION} | ips,
        )

    @validate_authentication
    def delete_ip_group_member(self, group_name: str, ip: str) -> Dict[str, Any]:
        """
        Delete an IP group member from IP group.

        Args:
            group_name (str): The name of the IP group.
            ip_mask (str): The IP address member to remove from the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "DELETE",
            f"api/v1/ProfIp_address_group/{group_name}/ProfIp_address_groupIpAddressGroupMember/{ip}",
        )

    @validate_authentication
    def list_ip_group_member(
        self,
        group_name: str,
        ip: str = None,
    ) -> Dict[str, Any]:
        """
        List IP group members by specify group member.
        If a IP is given, return the information about the specify IP group member.

        Args:

            ip (str, optional): The IP address to retrieve. Defaults to None.
            group_name (str, optional): The name of the IP group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "GET",
            f"api/v1/ProfIp_address_group/{group_name}/ProfIp_address_groupIpAddressGroupMember/",
            json_data=remove_empty_elements(
                {
                    "ip": ip,
                }
            ),
        )

    @validate_authentication
    def create_email_group(
        self,
        name: str,
        comment: str = None,
    ) -> Dict[str, Any]:
        """
        Create an email group. Email group is a container for a list of email addresses,
        allowing you to use it in configuring access control rules (for defining the sender
        and recipient matching) and recipient-based policies (for defining MAIL FROM addresses
        matching specific policies).

        Args:
            name (str): The name of the email group. The name must contain only alphanumeric characters.
                Spaces are not allowed.
            comment (str | None): A brief comment for the email group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            f"api/v1/ProfEmail_address_group/{name}/",
            json_data=remove_empty_elements({"comment": comment}),
        )

    @validate_authentication
    def update_email_group(
        self,
        name: str,
        comment: str,
    ) -> Dict[str, Any]:
        """
        Update the comment of an email group.

        Args:
            name (str): The name of the email group to update.
            comment (str): A brief comment for the email group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "PUT",
            f"api/v1/ProfEmail_address_group/{name}/",
            json_data={"comment": comment},
        )

    @validate_authentication
    def delete_email_group(self, name: str) -> Dict[str, Any]:
        """
        Delete an email group.

        Args:
            name (str | None): The name of the email group to remove.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request("DELETE", f"api/v1/ProfEmail_address_group/{name}")

    @validate_authentication
    def list_email_group(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List email groups. if a name is given, return the information about the specify email group.

        Args:

            name (str, optional): The name of the email group to retrieve. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            "GET",
            f"api/v1/ProfEmail_address_group{url_suffix}",
        )

    @validate_authentication
    def add_email_group_member(self, group_name: str, email: str) -> Dict[str, Any]:
        """
        Add an email group member (email address) to email group.

        Args:
            group_name (str): The name of the email group.
            email (str): The email address to include in the email group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            f"api/v1/ProfEmail_address_group/{group_name}/ProfEmail_address_groupEmailAddressGroupMember/{email}",
        )

    @validate_authentication
    def replace_email_group_member(
        self,
        group_name: str,
        emails: dict[str, str],
    ) -> Dict[str, Any]:
        """
        Replace Email group members with new members.
        This overwrites all the email group members that defined in the email group.

        Args:
            group_name (str): The name of the email group.
            emails (dict[str, str]): A list of email address (separated with a comma) to replace in the email group.

        Returns:
            Dict[str, Any]: The API response.
        """

        return self._http_request(
            "POST",
            f"api/v1/ProfEmail_address_group/{group_name}/ProfEmail_address_groupEmailAddressGroupMember",
            json_data={"reqAction": REPLACE_ACTION} | emails,
        )

    @validate_authentication
    def delete_email_group_member(self, group_name: str, email: str) -> Dict[str, Any]:
        """
        Delete an email group member from email group.

        Args:
            group_name (str): The name of the email group.
            email (str): The email member to remove from the email group.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "DELETE",
            f"api/v1/ProfEmail_address_group/{group_name}/ProfEmail_address_groupEmailAddressGroupMember/{email}",
        )

    @validate_authentication
    def list_email_group_member(
        self,
        group_name: str,
        email: str = None,
    ) -> Dict[str, Any]:
        """
        List email group members by specify group member.
        If an email is given, return the information about the specify email group member.

        Args:

            email (str, optional): The email member to retrieve. Defaults to None.
            group_name (str, optional): The name of the email group.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{email}" if email else ""
        return self._http_request(
            "GET",
            f"api/v1/ProfEmail_address_group/{group_name}/ProfEmail_address_groupEmailAddressGroupMember{url_suffix}",
        )

    @validate_authentication
    def list_system_safe_block(
        self,
        list_type: str,
    ) -> Dict[str, Any]:
        """
        List the system Block/Safe list. Choose the wanted list by the list_type argument.

        Args:
            list_type (str): The type of the list to retrieve.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/SenderListV2/system/",
            json_data={
                "extraParam": list_type.lower(),
                "reqAction": 1,
            },
        )

    @validate_authentication
    def add_system_safe_block(self, list_type: str, list_items: str) -> Dict[str, Any]:
        """
        Add an email address/ domain name/ IP address to the system white/ block list.

        Args:
            list_type (str): The type of the list to add the values.
            list_items (list[str]): Email address/ domain name/ IP address to add to the system white/ block list.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/SenderListV2/system",
            json_data={"extraParam": list_type.lower(), "listitems": list_items},
        )

    @validate_authentication
    def delete_system_safe_block(self, values: list[str], list_type: str) -> Dict[str, Any]:
        """
        Delete an email address/ domain name/ IP address from the system white/ block list.
        Choose the wanted list by the type argument.

        Args:
            values (list[str]): Email address/ domain name/ IP address (speretaed by comma) to remove
                from the system white/ block list. For example, test@test.com, test2@test.com or 1.1.1.1/0,1.1.1.2/0.
            list_type (str): The type of the list to add the values. Safelist - accept mesage, Blocklist
                invoke block list action that defined int the settings.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/SenderListV2/system/",
            json_data={"reqAction": 3, "extraParam": list_type.lower(), "listitems": values},
        )

    @validate_authentication
    def create_ip_policy(
        self,
        status: bool,
        action: int,
        use_smtp_auth: bool,
        smtp_different: bool,
        smtp_diff_identity_ldap: bool,
        exclusive: bool,
        destination: str = None,
        destination_type: int = None,
        source: str = None,
        source_type: int = None,
        auth_type: int = None,
        comment: str = None,
        antispam_profile: str = None,
        antivirus_profile: str = None,
        content_profile: str = None,
        session_profile: str = None,
        auth_profile: str = None,
        ip_pool_profile: str = None,
        smtp_diff_identity_ldap_profile: str = None,
    ) -> Dict[str, Any]:
        """
        Create an IP policy. IP-based policies lets you control emails based on
        IP/Netmask / IP Group/  GeoIP Group/ ISDB.

        Args:
            status (bool): Whether to apply the policy.
            action (int): An action for the policy.
            use_smtp_auth (bool): Whether to authenticate SMTP connections using the authentication profile configured
                in sensitive-data.
            smtp_different (bool):  Whether to reject different SMTP sender identity for authenticated user.
            smtp_diff_identity_ldap (bool): Whether to verify SMTP sender identity with LDAP for authenticated email.
            exclusive (bool): Whether to take precedence over recipient based policy match.
                Enable to omit use of recipient-based policies for connections matching this IP-based policy.
            destination (str, optional): The destination of the policy. Defaults to None.
            destination_type (int, optional): The type of the destination. Insert the source argument corresponding to
                the type value. Defaults to None.
            source (str, optional): The source of the policy. Defaults to None.
            source_type (int, optional): The type of the source. Insert the source argument corresponding to the type
                value. Defaults to None.
            auth_type (int, optional): The type of the authentication profile that this policy will apply.
                Defaults to None.
            comment (str, optional): A brief comment for the IP policy. Defaults to None.
            antispam_profile (str, optional): The name of an outgoing anti spam profile, if any, that this policy will
                apply. Defaults to None.
            antivirus_profile (str, optional): The name of an antivirus profile, if any, that this policy will apply.
                Defaults to None.
            content_profile (str, optional): The name of the content profile that you want to apply to connections
                matching the policy. Defaults to None.
            session_profile (str, optional): The name of the session profile that you want to apply to connections
                matching the policy. Defaults to None.
            auth_profile (str, optional): The name of an authentication profile for the type. Defaults to None.
            ip_pool_profile (str, optional): The name of an IP pool profile, if any, that this policy will apply.
                Defaults to None.
            smtp_diff_identity_ldap_profile (str, optional): LDAP profile for SMTP sender identity verification.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "action": action,
                "antispam_profile": antispam_profile,
                "antivirus_profile": antivirus_profile,
                "auth_type": auth_type,
                "client": source,
                "client_type": source_type,
                "client_geoip_group": source,
                "client_ip_group": source,
                "client_isdb": source,
                "comment": comment,
                "content_profile": content_profile,
                "exclusive": exclusive,
                "imap_auth": auth_profile,
                "ip_pool_profile": ip_pool_profile,
                "ldap_auth": auth_profile,
                "pop3_auth": auth_profile,
                "radius_auth": auth_profile,
                "server": destination,
                "server_type": destination_type,
                "server_ip_group": destination,
                "session_profile": session_profile,
                "smtp_auth": auth_profile,
                "smtp_diff_identity_ldap": smtp_diff_identity_ldap,
                "smtp_diff_identity_ldap_profile": smtp_diff_identity_ldap_profile,
                "smtp_different": smtp_different,
                "status": status,
                "use_smtp_auth": use_smtp_auth,
            }
        )
        return self._http_request("POST", "api/v1/PolicyIp/0", json_data=data)

    @validate_authentication
    def update_ip_policy(
        self,
        ip_policy_id: int,
        status: bool = None,
        destination: str = None,
        destination_type: int = None,
        source: str = None,
        source_type: int = None,
        action: int = None,
        use_smtp_auth: bool = None,
        smtp_different: bool = None,
        smtp_diff_identity_ldap: bool = None,
        exclusive: bool = None,
        auth_type: int = None,
        comment: str = None,
        antispam_profile: str = None,
        antivirus_profile: str = None,
        content_profile: str = None,
        session_profile: str = None,
        auth_profile: str = None,
        ip_pool_profile: str = None,
        smtp_diff_identity_ldap_profile: str = None,
    ) -> Dict[str, Any]:
        """
        Update an IP policy.

        Args:
            ip_policy_id (bool): The IP policy ID.
            status (bool): Whether to apply the policy. Defaults to None.
            action (int): An action for the policy. Defaults to None.
            use_smtp_auth (bool): Whether to authenticate SMTP connections using the authentication profile configured
                in sensitive-data. Defaults to None.
            smtp_different (bool):  Whether to reject different SMTP sender identity for authenticated user.
                Defaults to None.
            smtp_diff_identity_ldap (bool): Whether to verify SMTP sender identity with LDAP for authenticated email.
                Defaults to None.
            exclusive (bool): Whether to take precedence over recipient based policy match.
                Enable to omit use of recipient-based policies for connections matching this IP-based policy.
                Defaults to None.
            destination (str, optional): The destination of the policy. Defaults to None.
            destination_type (int, optional): The type of the destination. Insert the source argument corresponding to
                the type value. Defaults to None.
            source (str, optional): The source of the policy. Defaults to None.
            source_type (int, optional): The type of the source. Insert the source argument corresponding to the type
                value. Defaults to None.
            auth_type (int, optional): The type of the authentication profile that this policy will apply.
                Defaults to None.
            comment (str, optional): A brief comment for the IP policy. Defaults to None.
            antispam_profile (str, optional): The name of an outgoing anti spam profile, if any, that this policy will
                apply. Defaults to None.
            antivirus_profile (str, optional): The name of an antivirus profile, if any, that this policy will apply.
                Defaults to None.
            content_profile (str, optional): The name of the content profile that you want to apply to connections
                matching the policy. Defaults to None.
            session_profile (str, optional): The name of the session profile that you want to apply to connections
                matching the policy. Defaults to None.
            auth_profile (str, optional): The name of an authentication profile for the type. Defaults to None.
            ip_pool_profile (str, optional): The name of an IP pool profile, if any, that this policy will apply.
                Defaults to None.
            smtp_diff_identity_ldap_profile (str, optional): LDAP profile for SMTP sender identity verification.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "action": action,
                "antispam_profile": antispam_profile,
                "antivirus_profile": antivirus_profile,
                "auth_type": auth_type,
                "client": source,
                "client_type": source_type,
                "client_geoip_group": source,
                "client_ip_group": source,
                "client_isdb": source,
                "comment": comment,
                "content_profile": content_profile,
                "exclusive": exclusive,
                "imap_auth": auth_profile,
                "ip_pool_profile": ip_pool_profile,
                "ldap_auth": auth_profile,
                "pop3_auth": auth_profile,
                "radius_auth": auth_profile,
                "server": destination,
                "server_type": destination_type,
                "server_ip_group": destination,
                "session_profile": session_profile,
                "smtp_auth": auth_profile,
                "smtp_diff_identity_ldap": smtp_diff_identity_ldap,
                "smtp_diff_identity_ldap_profile": smtp_diff_identity_ldap_profile,
                "smtp_different": smtp_different,
                "status": status,
                "use_smtp_auth": use_smtp_auth,
            }
        )

        return self._http_request("PUT", f"api/v1/PolicyIp/{ip_policy_id}", json_data=data)

    @validate_authentication
    def move_ip_policy(self, policy_id: int, action: str, reference_id: int = None) -> Dict[str, Any]:
        """
        Move an IP policy location in the policy list.
        FortiMail units match the policies in sequence, from the top of the list downwards.
        Therefore, you must put the more specific policies on top of the more generic ones.

        Args:
            policy_id (int): The ID of the IP policy rule to be moved.
            action (str): The move action.
            reference_id (int, optional): The reference ID of the IP policy rule when moving before/after.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/PolicyIp",
            json_data=remove_empty_elements(
                {
                    "mmkey": policy_id,
                    "moveAction": action,
                    "reqAction": MOVE_ACTION,
                    "refMkey": reference_id,
                }
            ),
        )

    @validate_authentication
    def delete_ip_policy(self, policy_id: int) -> Dict[str, Any]:
        """
        Delete an IP policy.

        Args:
            policy_id (int): The ID of the IP policy to remove.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request("DELETE", f"api/v1/PolicyIp/{policy_id}")

    @validate_authentication
    def list_ip_policy(
        self,
        policy_id: str = None,
    ) -> Dict[str, Any]:
        """
        List IP policy. if a ID is given, return the information about the specify IP policy.

        Args:
            policy_id (str, optional): The ID of the IP policy to retrieve. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{policy_id}" if policy_id else ""
        return self._http_request(
            "GET",
            f"api/v1/PolicyIp{url_suffix}",
        )

    @validate_authentication
    def create_access_control(
        self,
        status: bool,
        sender_type: int,
        sender: str,
        recipient_type: int,
        recipient: str,
        action: int,
        source_type: str,
        authentication_status: int,
        sender_ldap_profile: str = None,
        recipient_ldap_profile: str = None,
        source: str = None,
        reverse_dns_pattern: str = None,
        reverse_dns_pattern_regex: bool = None,
        tls_profile: str = None,
        comment: str = None,
    ) -> Dict[str, Any]:
        """
        Create an Access control rule. Access control rules take effect after the FortiMail unit has initiated
        or received an IP and TCP-level connection at the application layer of the network.

        Args:
            status (bool): Whether to activate the access rule.
            sender_type (int): The method of the SMTP client attempting to send the email message.
            sender (str): The sender.
            recipient_type (int): The recipient pattern type.
            recipient (str): The recipient.
            action (int): The delivery action that FortiMail unit will perform for SMTP sessions matching this
                access control rule.
            source_type (str): The method of the SMTP client attempting to send the email message.
            authentication_status (int): Authentication status.
            sender_ldap_profile (str, optional): Sender LDAP profile. Relevant when sender_type= LDAP Group.
                Defaults to None.
            recipient_ldap_profile (str, optional): Recipient LDAP profile. Relevant when recipient_type= LDAP Group.
                Defaults to None.
            source (str, optional): When sender_type = IP/Netmask insert the source IP address and net-mask of the
                SMTP client attempting to send the email message. Defaults to None.
            reverse_dns_pattern (str, optional): A pattern to compare to the result of a reverse DNS look-up of the
                source IP address of the SMTP client attempting to send the email message. Defaults to None.
            reverse_dns_pattern_regex (str, optional): Whether to use regular expression syntax instead of wildcards
                to specify the reverse DNS pattern. Defaults to None.
            tls_profile (str, optional): A TLS profile to allow or reject the connection based on whether the
                communication session attributes match the settings in the TLS profile. Defaults to None.
            comment (str, optional):  A brief comment for the Access control. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "status": status,
                "sender_type": sender_type,
                "sender_pattern_group": sender,
                "sender_pattern_ldap_groupname": sender,
                "recipient_type": recipient_type,
                "recipient_pattern_group": recipient,
                "recipient_pattern_ldap_groupname": recipient,
                "sender_ldap_profile": sender_ldap_profile,
                "recipient_ldap_profile": recipient_ldap_profile,
                "source_type": source_type,
                "sender_geoip_group": source,
                "sender_ip_mask": source,
                "sender_ip_group": source,
                "sender_isdb": source,
                "reverse_dns_pattern": reverse_dns_pattern,
                "reverse_dns_pattern_regex": reverse_dns_pattern_regex,
                "authentication_status": authentication_status,
                "tls_profile": tls_profile,
                "action": action,
                "comment": comment,
            }
        )
        return self._http_request("POST", "api/v1/MailSetAccessRule/0", json_data=data)

    @validate_authentication
    def update_access_control(
        self,
        access_control_id: int,
        status: bool = None,
        sender_type: int = None,
        sender: str = None,
        recipient_type: int = None,
        recipient: str = None,
        action: int = None,
        source_type: str = None,
        authentication_status: int = None,
        sender_ldap_profile: str = None,
        recipient_ldap_profile: str = None,
        source: str = None,
        reverse_dns_pattern: str = None,
        reverse_dns_pattern_regex: bool = None,
        tls_profile: str = None,
        comment: str = None,
    ) -> Dict[str, Any]:
        """
        Update an Access control rule. Access control rules take effect after the FortiMail unit has initiated
        or received an IP and TCP-level connection at the application layer of the network.

        Args:
            access_control_id (bool): The access control ID.
            status (bool): Whether to activate the access rule.
            sender_type (int): The method of the SMTP client attempting to send the email message.
            sender (str): The sender.
            recipient_type (int): The recipient pattern type.
            recipient (str): The recipient.
            action (int): The delivery action that FortiMail unit will perform for SMTP sessions matching this
                access control rule.
            source_type (str): The method of the SMTP client attempting to send the email message.
            authentication_status (int): Authentication status.
            sender_ldap_profile (str, optional): Sender LDAP profile. Relevant when sender_type= LDAP Group.
                Defaults to None.
            recipient_ldap_profile (str, optional): Recipient LDAP profile. Relevant when recipient_type= LDAP Group.
                Defaults to None.
            source (str, optional): When sender_type = IP/Netmask insert the source IP address and net-mask of the
                SMTP client attempting to send the email message. Defaults to None.
            reverse_dns_pattern (str, optional): A pattern to compare to the result of a reverse DNS look-up of the
                source IP address of the SMTP client attempting to send the email message. Defaults to None.
            reverse_dns_pattern_regex (str, optional): Whether to use regular expression syntax instead of wildcards
                to specify the reverse DNS pattern. Defaults to None.
            tls_profile (str, optional): A TLS profile to allow or reject the connection based on whether the
                communication session attributes match the settings in the TLS profile. Defaults to None.
            comment (str, optional):  A brief comment for the Access control. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "status": status,
                "sender_type": sender_type,
                "sender_pattern_group": sender,
                "sender_pattern_ldap_groupname": sender,
                "recipient_type": recipient_type,
                "recipient_pattern_group": recipient,
                "recipient_pattern_ldap_groupname": recipient,
                "sender_ldap_profile": sender_ldap_profile,
                "recipient_ldap_profile": recipient_ldap_profile,
                "source_type": source_type,
                "sender_geoip_group": source,
                "sender_ip_mask": source,
                "sender_ip_group": source,
                "sender_isdb": source,
                "reverse_dns_pattern": reverse_dns_pattern,
                "reverse_dns_pattern_regex": reverse_dns_pattern_regex,
                "authentication_status": authentication_status,
                "tls_profile": tls_profile,
                "action": action,
                "comment": comment,
            }
        )

        return self._http_request("PUT", f"api/v1/MailSetAccessRule/{access_control_id}", json_data=data)

    @validate_authentication
    def delete_access_control(self, access_control_id: int) -> Dict[str, Any]:
        """
        Delete an access control rule.

        Args:
            access_control_id (int): The ID of the access rule to remove.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request("DELETE", f"api/v1/MailSetAccessRule/{access_control_id}")

    @validate_authentication
    def move_access_control(self, access_control_id: int, action: str, reference_id: int = None) -> Dict[str, Any]:
        """
        Move an Access control rule location in the rules list.
        FortiMail units match the policies in sequence, from the top of the list downwards.
        Therefore, you must put the more specific policies on top of the more generic ones.

        Args:
            access_control_id (int): The ID of the access control to be moved.
            action (str): The move action.
            reference_id (int, optional): The reference ID of the access control rule when moving before/after.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/MailSetAccessRule",
            json_data=remove_empty_elements(
                {
                    "mmkey": access_control_id,
                    "moveAction": action,
                    "reqAction": MOVE_ACTION,
                    "refMkey": reference_id,
                }
            ),
        )

    @validate_authentication
    def list_access_control(
        self,
        access_control_id: int = None,
    ) -> Dict[str, Any]:
        """
        List access control rules. if a ID is given, return the information about the wanted access control rule.

        Args:
            access_control_id (str, optional): The ID of the IP policy to retrieve. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{access_control_id}" if access_control_id else ""
        return self._http_request(
            "GET",
            f"api/v1/MailSetAccessRule{url_suffix}",
        )

    @validate_authentication
    def create_recipient_policy(
        self,
        status: bool,
        direction: int,
        use_smtp_auth: bool,
        smtp_different: bool,
        smtp_diff_identity_ldap: bool,
        enable_pki: bool,
        certificate_validation: bool,
        recipient_email_address_group: str = None,
        sender_email_address_group: str = None,
        auth_type: int = None,
        sender_type: int = None,
        recipient_type: int = None,
        comment: str = None,
        sender_pattern: str = None,
        sender_ldap_profile: str = None,
        recipient_pattern: str = None,
        recipient_ldap_profile: str = None,
        antispam_profile: str = None,
        antivirus_profile: str = None,
        content_profile: str = None,
        resource_profile: str = None,
        auth_profile: str = None,
        pki_profile: str = None,
        smtp_diff_identity_ldap_profile: str = None,
    ) -> Dict[str, Any]:
        """
        Create an Inbound/ Outbound Recipient policy.
        Recipient policies control email based on sender and recipient addresses.
        Recipient-based policies have precedence if an IP-based policy is also applicable but conflicts.

        Args:
            status (bool): Whether to apply the policy.
            direction (int): The mail traffic direction.
            use_smtp_auth (str): Whether to authenticate SMTP connections using the authentication profile
                configured in sensitive-data.
            smtp_different (bool): Whether to reject different SMTP sender identity for authenticated user.
            smtp_diff_identity_ldap (str): Whether to verify SMTP sender identity with LDAP for authenticated email.
            enable_pki (str): Whether to allow email users to log in to their per-recipient spam quarantine by
                presenting a certificate rather than a user name and password.
            certificate_validation (str): Whether to require valid certificates only and disallow password-style
                fallback.
            recipient_email_address_group (str, optional): Recipient Email group.
                Relevant when recipient_type=Email address group. Defaults to None.
            sender_email_address_group (str, optional): Sender Email group.
                Relevant when recipient_type=Email address group. Defaults to None.
            auth_type (int, optional): The type of the authentication profile that this policy will apply.
                Defaults to None.
            sender_type (int, optional): Define sender (MAIL FROM:) email addresses that match this policy.
                Defaults to None.
            recipient_type (int, optional): Define recipient (RCPT TO:) email addresses that match this policy.
                Defaults to None.
            comment (str, optional): A brief comment for the recipient policy. Defaults to None.
            sender_pattern (str, optional): The policy sender pattern. Defaults to None.
            sender_ldap_profile (str, optional): Sender LDAP profile. Relevant when sender_type=LDAP Group.
                Defaults to None.
            recipient_pattern (str, optional): The policy recipient pattern. Defaults to None.
            recipient_ldap_profile (str, optional): Recipient LDAP profile. Relevant when recipient_type=LDAP Group.
                Defaults to None.
            antispam_profile (str, optional): The name of an outgoing anti spam profile, if any, that this policy
                will apply. Defaults to None.
            antivirus_profile (str, optional): The name of an antivirus profile, if any, that this policy will apply.
                Defaults to None.
            content_profile (str, optional): The name of the content profile that you want to apply to connections
                matching the policy. Defaults to None.
            resource_profile (str, optional): The name of the resource profile that you want to apply to connections
                matching the policy. Defaults to None.
            auth_profile (str, optional): The name of an authentication profile for the type. Defaults to None.
            pki_profile (str, optional): The name of a PKI user. Relevant when enable_pki is enable. Defaults to None.
            smtp_diff_identity_ldap_profile (str, optional): LDAP profile for SMTP sender identity verification.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "status": status,
                "direction": direction,
                "use_smtp_auth": use_smtp_auth,
                "smtp_different": smtp_different,
                "smtp_diff_identity_ldap": smtp_diff_identity_ldap,
                "enable_pki": enable_pki,
                "certificate_validation": certificate_validation,
                "comment": comment,
                "recipient_email_address_group": recipient_email_address_group,
                "sender_email_address_group": sender_email_address_group,
                "sender_type": sender_type,
                "sender_pattern": sender_pattern,
                "sender_ldap_profile": sender_ldap_profile,
                "recipient_type": recipient_type,
                "recipient_pattern": recipient_pattern,
                "recipient_ldap_profile": recipient_ldap_profile,
                "antispam": antispam_profile,
                "antivirus": antivirus_profile,
                "content": content_profile,
                "misc": resource_profile,
                "auth_profile": auth_profile,
                "pki_profile": pki_profile,
                "auth": auth_type,
                "smtp_diff_identity_ldap_profile": smtp_diff_identity_ldap_profile,
            }
        )

        return self._http_request("POST", "api/v1/PolicyRcpt/0", json_data=data)

    @validate_authentication
    def update_recipient_policy(
        self,
        recipient_policy_id: int,
        status: bool = None,
        direction: int = None,
        use_smtp_auth: bool = None,
        smtp_different: bool = None,
        smtp_diff_identity_ldap: bool = None,
        enable_pki: bool = None,
        certificate_validation: bool = None,
        recipient_email_address_group: str = None,
        sender_email_address_group: str = None,
        auth_type: int = None,
        sender_type: int = None,
        recipient_type: int = None,
        comment: str = None,
        sender_pattern: str = None,
        sender_ldap_profile: str = None,
        recipient_pattern: str = None,
        recipient_ldap_profile: str = None,
        antispam_profile: str = None,
        antivirus_profile: str = None,
        content_profile: str = None,
        resource_profile: str = None,
        auth_profile: str = None,
        pki_profile: str = None,
        smtp_diff_identity_ldap_profile: str = None,
    ) -> Dict[str, Any]:
        """
        Update an Inbound/ Outbound Recipient policy.
        Recipient policies control email based on sender and recipient addresses.
        Recipient-based policies have precedence if an IP-based policy is also applicable but conflicts.

        Args:
            recipient_policy_id (int): The recipient policy ID.
            status (bool): Whether to apply the policy.
            direction (int): The mail traffic direction.
            use_smtp_auth (str): Whether to authenticate SMTP connections using the authentication profile configured
                in sensitive-data.
            smtp_different (bool): Whether to reject different SMTP sender identity for authenticated user.
            smtp_diff_identity_ldap (str): Whether to verify SMTP sender identity with LDAP for authenticated email.
            enable_pki (str): Whether to allow email users to log in to their per-recipient spam quarantine by
                presenting a certificate rather than a user name and password.
            certificate_validation (str): Whether to require valid certificates only and disallow
                password-style fallback.
            recipient_email_address_group (str, optional): Recipient Email group.
                Relevant when recipient_type=Email address group. Defaults to None.
            sender_email_address_group (str, optional): Sender Email group.
                Relevant when recipient_type=Email address group. Defaults to None.
            auth_type (int, optional): The type of the authentication profile that this policy will apply.
                Defaults to None.
            sender_type (int, optional): Define sender (MAIL FROM:) email addresses that match this policy.
                Defaults to None.
            recipient_type (int, optional): Define recipient (RCPT TO:) email addresses that match this policy.
                Defaults to None.
            comment (str, optional): A brief comment for the recipient policy. Defaults to None.
            sender_pattern (str, optional): The policy sender pattern. Defaults to None.
            sender_ldap_profile (str, optional): Sender LDAP profile. Relevant when sender_type=LDAP Group.
                Defaults to None.
            recipient_pattern (str, optional): The policy recipient pattern. Defaults to None.
            recipient_ldap_profile (str, optional): Recipient LDAP profile. Relevant when recipient_type=LDAP Group.
                Defaults to None.
            antispam_profile (str, optional): The name of an outgoing anti spam profile, if any, that this policy
                will apply. Defaults to None.
            antivirus_profile (str, optional): The name of an antivirus profile, if any, that this policy will apply.
                Defaults to None.
            content_profile (str, optional): The name of the content profile that you want to apply to connections
                matching the policy. Defaults to None.
            resource_profile (str, optional): The name of the resource profile that you want to apply to connections
                matching the policy. Defaults to None.
            auth_profile (str, optional): The name of an authentication profile for the type. Defaults to None.
            pki_profile (str, optional): The name of a PKI user. Relevant when enable_pki is enable. Defaults to None.
            smtp_diff_identity_ldap_profile (str, optional): LDAP profile for SMTP sender identity verification.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        data = remove_empty_elements(
            {
                "status": status,
                "direction": direction,
                "use_smtp_auth": use_smtp_auth,
                "smtp_different": smtp_different,
                "smtp_diff_identity_ldap": smtp_diff_identity_ldap,
                "enable_pki": enable_pki,
                "certificate_validation": certificate_validation,
                "comment": comment,
                "recipient_email_address_group": recipient_email_address_group,
                "sender_email_address_group": sender_email_address_group,
                "sender_type": sender_type,
                "sender_pattern": sender_pattern,
                "sender_ldap_profile": sender_ldap_profile,
                "recipient_type": recipient_type,
                "recipient_pattern": recipient_pattern,
                "recipient_ldap_profile": recipient_ldap_profile,
                "antispam_profile": antispam_profile,
                "antivirus_profile": antivirus_profile,
                "content_profile": content_profile,
                "resource_profile": resource_profile,
                "auth_profile": auth_profile,
                "pki_profile": pki_profile,
                "auth_type": auth_type,
                "smtp_diff_identity_ldap_profile": smtp_diff_identity_ldap_profile,
            }
        )
        return self._http_request("PUT", f"api/v1/PolicyRcpt/{recipient_policy_id}", json_data=data)

    @validate_authentication
    def delete_recipient_policy(self, recipient_policy_id: int) -> Dict[str, Any]:
        """
        Delete a recipient policy.

        Args:
            recipient_policy_id (int): The ID of the recipient policy to be remove.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request("DELETE", f"api/v1/domain/system/PolicyRcpt/{recipient_policy_id}")

    @validate_authentication
    def move_recipient_policy(self, recipient_policy_id: int, action: str, reference_id: int = None) -> Dict[str, Any]:
        """
        Move a recipient policy location in the policy list.
        FortiMail units match the policies in sequence, from the top of the list downwards.
        Therefore, you must put the more specific policies on top of the more generic ones

        Args:
            access_control_id (int): The ID of the recipient policy to be moved.
            action (str): The move action.
            reference_id (int, optional): The reference ID of the recipient policy when moving before/after.
                Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        return self._http_request(
            "POST",
            "api/v1/domain/system/PolicyRcpt",
            json_data=remove_empty_elements(
                {
                    "mmkey": recipient_policy_id,
                    "moveAction": action,
                    "reqAction": MOVE_ACTION,
                    "refMkey": reference_id,
                }
            ),
        )

    @validate_authentication
    def list_recipient_policy(
        self,
        recipient_policy_id: str = None,
    ) -> Dict[str, Any]:
        """
        List recipient policies. If a recipient_policy_id is given, return the information about the wanted recipient policy.

        Args:
            recipient_policy_id (str, optional): The ID of the recipient policy. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{recipient_policy_id}" if recipient_policy_id else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/domain/system/PolicyRcpt{url_suffix}",
        )

    @validate_authentication
    def list_tls_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List TLS profiles.
        TLS profiles allow you to selectively disable or enable TLS for specific email recipient patterns,
        IP subnets, and so on.
        A common use of TLS profiles is to enforce TLS transport to a specific domain and verify the certificate
        of the receiving servers.
        if an name is given, return the information about the wanted TLS profile.
        Mainly used in the configuration of Access control rule.

        Args:
            name (str, optional): The name of the TLS profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfTls{url_suffix}",
        )

    @validate_authentication
    def list_ldap_group(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List LDAP profiles. LDAP groups lets to allow match email addresses as sender or recipients
        with the LDAP profile authentication in the Access control rule configuration and is the authentication
        profile in case the authentication type in IP policy is LDAP.
        if an name is given, return the information about the wanted LDAP profile.
        Mainly used in the configuration of Access control rule and the IP policy.

        Args:
            name (str, optional): The name of the anti spam LDAP profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfLdap{url_suffix}",
        )

    @validate_authentication
    def list_geoip_group(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List GeoIP groups.
        FortiMail utilizes the GeoIP database to map the geo locations of client IP addresses.
        You can use GeoIP groups in access control rules and IP-based policies to geo-targeting spam and virus devices.
        if an name is given, return the information about the wanted GeoIP profile.
        Mainly used in the configuration of Access control rule and the IP policy.

        Args:
            name (str, optional): The name of the anti spam GeoIP group. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfGeoip{url_suffix}",
        )

    @validate_authentication
    def list_antispam_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List AntiSpam profiles.
        Antispam profiles are sets of antispam scans that you can apply by selecting one in a policy.
        if an name is given, return the information about the wanted AntiSpam profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the anti spam profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAntispam{url_suffix}",
        )

    @validate_authentication
    def list_antivirus_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List AntiVirus profiles. if the FortiMail unit detects a virus, it will take actions as you define in
        the antivirus action profiles.
        if an name is given, return the information about the wanted AntiVirus profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the anti virus profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAntivirus{url_suffix}",
        )

    @validate_authentication
    def list_content_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List Content profiles.
        Content profile lets to allow match email based upon its subject line, message body, and attachments.
        if an name is given, return the information about the wanted content profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the content profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfContent{url_suffix}",
        )

    @validate_authentication
    def list_ip_pool(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List IP pool profiles.
        IP pools define a range of IP addresses, and can be used in multiple ways:
        To define source IP addresses used by the FortiMail unit if you want outgoing email to originate
        from a range of IP addresses.
        To define destination addresses used by the FortiMail unit if you want incoming email to destine
        to the virtual host on a range of IP addresses. if an name is given, return the
        information about the wanted IP pool.  Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the IP pool. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfIp_pool{url_suffix}",
        )

    @validate_authentication
    def list_session_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List IP session profiles. Session profiles focus on the connection and envelope portion of the SMTP session.
        If a name is given, return the information about the wanted session profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the session profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfSession{url_suffix}",
        )

    @validate_authentication
    def list_radius_auth_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List RADIUS authentication profiles. if an name is given, return the information about
        the wanted RADIUS authentication profile. Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the RADIUS auth profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAuthRadius{url_suffix}",
        )

    @validate_authentication
    def list_pop3_auth_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List POP3 authentication profiles.
        if an name is given, return the information about the wanted POP3 authentication profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the POP3 auth profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAuthPop3{url_suffix}",
        )

    @validate_authentication
    def list_imap_auth_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List IMAP authentication profiles.
        if an name is given, return the information about the wanted IMAP authentication profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the IMAP auth profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAuthImap{url_suffix}",
        )

    @validate_authentication
    def list_smtp_auth_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List SMTP authentication profiles.
        if an name is given, return the information about the wanted SMTP authentication profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the SMTP auth profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfAuthSmtp{url_suffix}",
        )

    @validate_authentication
    def list_resource_profile(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List resource profiles.
        Resource profile configure miscellaneous aspects of the email user accounts, such as disk space quota.
        If an name is given, return the information about the wanted resource profile.
        Mainly used in the configuration of IP policy.

        Args:
            name (str, optional): The name of the resource profile. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""
        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/ProfMisc{url_suffix}",
        )

    @validate_authentication
    def list_pki_user(
        self,
        name: str = None,
    ) -> Dict[str, Any]:
        """
        List PKI users.
        PKI users can authenticate by presenting a valid client certificate,
        rather than by entering a username and password.
        If an name is given, return the information about the wanted PKI user.
        Mainly used in the configuration of recipient policy.

        Args:
            name (str, optional): The name of the PKI user. Defaults to None.

        Returns:
            Dict[str, Any]: The API response.
        """
        url_suffix = f"/{name}" if name else ""

        return self._http_request(
            method="GET",
            url_suffix=f"api/v1/UserPki{url_suffix}",
        )


# COMMANDS FUNCTIONS #


def add_system_safe_block_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Add an email address/ domain name/ IP address to the system white/ block list.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    list_type = args.get("list_type", "")
    list_items = args.get("values")

    response = client.add_system_safe_block(list_type, list_items)
    items = argToList(list_items)

    return CommandResults(
        readable_output=f"Items: {items} Were Added Successfully to System {list_type.removesuffix('list')} List",
        raw_response=response,
    )


def ip_policy_create_update_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Create or update IP policy.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)

    command_args = handle_ip_policy_command_args(args=args)

    response = command_request(**command_args)
    response = map_api_response_values_to_readable_string(response)
    output_table, _ = prepare_outputs_and_readable_output(output=response, command_args=command_args)

    readable_output = tableToMarkdown(
        name=command_entity_title,
        t=remove_empty_elements(output_table),
        removeNull=True,
    )
    return CommandResults(
        readable_output=readable_output,
        outputs_prefix="FortiMail.IPPolicy",
        outputs_key_field="mkey",
        outputs=response,
        raw_response=response,
    )


def access_control_create_update_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Create or update access control.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)

    command_args = handle_access_control_command_args(args=args)

    response = command_request(**command_args)
    response = map_api_response_values_to_readable_string(response)
    output_table, _ = prepare_outputs_and_readable_output(output=response, command_args=command_args)

    readable_output = tableToMarkdown(
        name=command_entity_title,
        t=remove_empty_elements(output_table),
        removeNull=True,
    )
    return CommandResults(
        readable_output=readable_output,
        outputs_prefix="FortiMail.AccessControl",
        outputs_key_field="mkey",
        outputs=response,
        raw_response=response,
    )


def recipient_policy_create_update_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Create or update recipient policy.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)

    command_args = handle_recipient_policy_command_args(args=args)

    response = command_request(**command_args)
    response = map_api_response_values_to_readable_string(response)
    output_table, _ = prepare_outputs_and_readable_output(output=response, command_args=command_args)

    readable_output = tableToMarkdown(
        name=command_entity_title,
        t=remove_empty_elements(output_table),
        removeNull=True,
    )
    return CommandResults(
        readable_output=readable_output,
        outputs_prefix="FortiMail.RecipientPolicy",
        outputs_key_field="mkey",
        outputs=response,
        raw_response=response,
    )


def move_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Move a recipient policy/ access control/ IP policy location in the policy list.
    FortiMail units match the policies in sequence, from the top of the list downwards.
    Therefore, you must put the more specific policies on top of the more generic ones.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)

    command_args = remove_empty_elements(
        {
            "access_control_id": args.get("access_control_id"),
            "policy_id": args.get("policy_id"),
            "recipient_policy_id": args.get("recipient_policy_id"),
            "action": args.get("action"),
            "reference_id": args.get("reference_id"),
        }
    )

    command_request(**command_args)

    return CommandResults(
        readable_output=command_entity_title,
    )


def list_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Return the items list according the command entity name.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, command_outputs_prefix = get_command_entity(command_name=command_name)

    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)

    # Get the relevant item key to fetch in case user use the command as GET.
    # Those arguments cover 22 list commands.
    command_args = handle_list_command_args(args=args)

    response = command_request(**command_args)
    # Map the response fields values from integer to string to be informative.
    output = map_api_response_values_to_readable_string(response)

    if not argToBoolean(args.get("all_results")):
        output = output[: arg_to_number(args.get("limit"))]

    output_table, output = prepare_outputs_and_readable_output(output=output, command_args=command_args)

    if not command_args:
        # Case list and not a get command.
        command_entity_title = f"{command_entity_title} list"

    readable_output = tableToMarkdown(
        name=command_entity_title,
        t=remove_empty_elements(output_table),
        # Add ordered headers keys by the updated outputs.
        headers=list(output_table[0]) if output_table else [],
        removeNull=True,
    )

    return CommandResults(
        readable_output=readable_output,
        outputs_prefix=f"FortiMail.{command_outputs_prefix}",
        # Handle output_key_field for system safe block list command that has a different response structure.
        outputs_key_field="item" if command_args.get("list_type") else "mkey",
        outputs=output,
        raw_response=response,
    )


def group_create_update_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Create or update IP/Email group, according the command entity name and operator.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, command_outputs_prefix = get_command_entity(command_name=command_name)

    command_args = remove_empty_elements(
        {
            "name": args.get("name"),
            "comment": args.get("comment"),
        }
    )
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)
    response = command_request(**command_args)
    # Get updated output for created/updated group
    output = {key: response[key] for key in ["mkey", "comment"] if key in response}

    readable_output = tableToMarkdown(
        name=command_entity_title,
        t=output,
        removeNull=True,
    )

    return CommandResults(
        readable_output=readable_output,
        outputs_prefix=f"FortiMail.{command_outputs_prefix}",
        outputs_key_field="mkey",
        outputs=output,
        raw_response=response,
    )


def delete_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Delete, according the command entity name, one of the following:
    IP group, Email group, IP group member, Email group member,
    System list items, IP policy, Access control, Recipient policy.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the 'delete' request function by command name.
    delete_request: Callable = get_command_request(command_name=command_name, client=client)
    # Get the relevant item key to remove
    command_args = handle_delete_command_args(args=args)

    validate_value_exist_before_delete(client=client, command_args=command_args, command_name=command_name)

    delete_request(**command_args)

    return CommandResults(readable_output=command_entity_title)


def group_member_add_replace_command(client: Client, args: Dict[str, Any]) -> CommandResults:
    """
    Add or replace, IP/email group member, according the command entity name and operator.

    Args:
        client (Client): Session to FortiMail to run API requests.
        args (dict[str, Any]): Arguments passed down by the CLI to configure the request.

    Returns:
        CommandResults: Outputs of the command that represent an entry in war room.
    """
    is_valid_email(args.get("email", args.get("emails")))
    command_name: str = args.get("command_name", "")
    command_entity_title, _ = get_command_entity(command_name=command_name)
    # Get the client request function by command name.
    command_request: Callable = get_command_request(command_name=command_name, client=client)
    command_args = remove_empty_elements(
        {
            "group_name": args.get("group_name"),
            "ip": args.get("ip"),
            "email": args.get("email"),
            "ips": argToList(args.get("ips")),
            "emails": argToList(args.get("emails")),
        }
    )

    updated_args = update_group_member_args(command_args=command_args)
    command_request(**updated_args)

    return CommandResults(readable_output=command_entity_title)


def test_module(client: Client) -> str:
    """
    Tests API connectivity and authentication.

    Returning 'ok' indicates that the integration works like it is supposed to.
    Raises exceptions if something goes wrong.

    Args:
        client (Client): Session to Fortimail to run API requests.

    Raises:
        DemistoException: Incase there is an unknown error.

    Returns:
        str: : 'ok' if test passed, or an error message if were too many login attempts
            or credentials are incorrect.
    """

    client.list_pki_user()
    return "ok"


# Helper Functions #


def is_valid_email(emails: List[str] | str | None):
    """
    Validate email addresses.

    Args:
        emails (List[str] | str): Emails to validate.

    Raises:
        DemistoException: Exception if email is invalid.
    """
    if not emails:
        return

    emails = emails if isinstance(emails, list) else [emails]
    for email in emails:
        if not re.match(emailRegex, email):
            raise DemistoException(f"{email} is not a valid email address.")


def map_api_response_values_to_readable_string(response: dict[str, Any]) -> list[dict[str, Any]]:
    """
    Update the response integer values to readable strings by existing mappers.
    The mapper used to map input arguments from string to integer for the API call
    and the reversed map used to map the response data to human readable.

    Args:
        response (dict[str, Any]): The API response.

    Returns:
        dict[str, Any]: The updated response.
    """
    updated_response = response.get("collection", [response])
    # Remove irrelevant keys from response
    object_id = response.pop("objectID", None)
    response.pop("reqAction", None)
    response.pop("nodePermission", None)

    if object_id:
        boolean_mapper = reverse_dict(BOOLEAN_MAPPER)

        if "MailSetAccessRule" in object_id:
            updated_response = map_access_control_response(
                updated_response=updated_response,
                boolean_mapper=boolean_mapper,
            )

        elif "PolicyRcpt" in object_id:
            updated_response = map_recipient_policy_response(
                updated_response=updated_response,
                boolean_mapper=boolean_mapper,
            )

        elif "PolicyIp" in object_id:
            updated_response = map_ip_policy_response(
                updated_response=updated_response,
                boolean_mapper=boolean_mapper,
            )

    return remove_empty_elements(updated_response)


def map_access_control_response(
    updated_response: list[dict[str, Any]],
    boolean_mapper: dict[str, Any],
) -> list[dict[str, Any]]:
    """
    Map access control response values to readable string.

    Args:
        updated_response (list[dict[str, Any]]): The API response.
        boolean_mapper (dict[str, Any]): Boolean mapper for enable and disable values.

    Returns:
        list[dict[str, Any]]: The updated response.
    """
    pattern_type_mapper = reverse_dict(AC_PATTERN_TYPE_MAPPER)
    auth_mapper = reverse_dict(AC_AUTH_MAPPER)
    sender_ip_type_mapper = reverse_dict(AC_SENDER_IP_TYPE_MAPPER)
    action_mapper = reverse_dict(AC_ACTION_MAPPER)

    for item in updated_response:
        item["sender_pattern_type"] = pattern_type_mapper.get(item.get("sender_pattern_type", ""))
        item["recipient_pattern_type"] = pattern_type_mapper.get(item.get("recipient_pattern_type", ""))
        item["sender_ip_type"] = sender_ip_type_mapper.get(item.get("sender_ip_type", ""))
        item["authenticated"] = auth_mapper.get(item.get("authenticated", ""))
        item["action"] = action_mapper.get(item.get("action", ""))
        item["status"] = boolean_mapper.get(item.get("status", ""))

    return updated_response


def map_recipient_policy_response(
    updated_response: list[dict[str, Any]],
    boolean_mapper: dict[str, Any],
) -> list[dict[str, Any]]:
    """
    Map recipient policy response values to readable string.

    Args:
        updated_response (list[dict[str, Any]]): The API response.
        boolean_mapper (dict[str, Any]): Boolean mapper for enable and disable values.

    Returns:
        list[dict[str, Any]]: The updated response.
    """
    direction_mapper = reverse_dict(RP_DIRECTION_MAPPER)
    auth_mapper = reverse_dict(RP_AUTH_MAPPER)
    pattern_type = reverse_dict(RP_PATTERN_TYPE_MAPPER)

    for item in updated_response:
        item["direction"] = direction_mapper.get(item.get("direction", ""))
        item["auth"] = auth_mapper.get(item.get("auth", ""))
        item["sender_type"] = pattern_type.get(item.get("sender_type", ""))
        item["status"] = boolean_mapper.get(item.get("status", ""))
        item["use_smtp_auth"] = boolean_mapper.get(item.get("use_smtp_auth", ""))
        item["smtp_different"] = boolean_mapper.get(item.get("smtp_different", ""))
        item["smtp_diff_identity_ldap"] = boolean_mapper.get(item.get("smtp_diff_identity_ldap", ""))
        item["pkiauth"] = boolean_mapper.get(item.get("pkiauth", ""))

    return updated_response


def map_ip_policy_response(
    updated_response: list[dict[str, Any]],
    boolean_mapper: dict[str, Any],
) -> list[dict[str, Any]]:
    """
    Map IP policy response values to readable string.

    Args:
        updated_response (list[dict[str, Any]]): The API response.
        boolean_mapper (dict[str, Any]): Boolean mapper for enable and disable values.

    Returns:
        list[dict[str, Any]]: The updated response.
    """
    destination_mapper = reverse_dict(DESTINATION_MAPPER)
    auth_mapper = reverse_dict(RP_AUTH_MAPPER)
    ip_action_mapper = reverse_dict(IP_ACTION_MAPPER)
    source_ip_type_mapper = reverse_dict(AC_SENDER_IP_TYPE_MAPPER)

    for item in updated_response:
        item["client_type"] = source_ip_type_mapper.get(item.get("client_type", ""))
        item["server_type"] = destination_mapper.get(item.get("server_type", ""))
        item["action"] = ip_action_mapper.get(item.get("action", ""))
        item["auth_type"] = auth_mapper.get(item.get("auth_type", ""))
        item["status"] = boolean_mapper.get(item.get("status", ""))
        item["exclusive"] = boolean_mapper.get(item.get("exclusive", ""))
        item["use_smtp_auth"] = boolean_mapper.get(item.get("use_smtp_auth", ""))
        item["smtp_different"] = boolean_mapper.get(item.get("smtp_different", ""))
        item["smtp_diff_identity_ldap"] = boolean_mapper.get(item.get("smtp_diff_identity_ldap", ""))

    return updated_response


def reverse_dict(original_dict: dict[str, Any]) -> dict[str, Any]:
    """
    Reverse the keys and values of a given dictionary.

    Args:
        original_dict (dict[str, Any]): The dictionary to be reversed.

    Returns:
        dict[str, Any]: A new dictionary with keys and values swapped.
    """
    return {value: key for key, value in original_dict.items()}


def convert_cidr_to_ip_range(item: str) -> str:
    """
    Convert CIDR to IP range.

    Args:
        item (str): optional CIDR.

    Returns:
        str: IP range.
    """
    if "-" in item:
        return item

    ip_data = item.split("/")
    return f"{ip_data[0]}-{ip_data[0]}"


def prepare_outputs_for_system_list(
    list_items: list[str],
    command_args: Dict[str, Any],
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
    """
    Update the system list API response keys names according to Fortimail UI, for the readable output.

    Args:
        list_items (list[str]): The system list items.
        command_args (Dict[str, Any]): The list command arguments.

    Returns:
        Tuple[list[dict[str, Any]], list[dict[str, Any]]]: New readable output and Updated response.
    """
    values = argToList(list_items)
    output_table = [{"item": value, "list_type": command_args.get("list_type")} for value in values]
    return output_table, output_table


def prepare_outputs_and_readable_output(
    output: list[dict[str, Any]],
    command_args: Dict[str, Any],
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
    """
    Update the API response keys names according to Fortimail UI, for the readable output.

    Args:
        output (list[dict[str, Any]]): The API response.
        command_args (Dict[str, Any]): The list command arguments.

    Returns:
        Tuple[list[dict[str, Any]], list[dict[str, Any]]]: New readable output and Updated response.
    """
    output_table = []

    for item in output:
        if list_items := item.get("listitems"):
            return prepare_outputs_for_system_list(list_items=list_items, command_args=command_args)
        # Build an ordered output table, response field value by header.
        # Map API response common fields (common for all commands).
        output_table.append(
            {
                "Name": item.get("mkey"),
                "Comment": item.get("comment"),
                "TLS level": item.get("level"),
                "Action On Failure": item.get("action"),
                "IP Group": item.get("ip_range"),
                "Server": item.get("server"),
                "Server Type": item.get("server_type"),
                "Client": item.get("client"),
                "Client Type": item.get("client_type"),
                "Auth Type": item.get("auth_type"),
                "Port": item.get("port"),
                "Status": item.get("status"),
                "Action": item.get("action"),
                "Authenticated": item.get("authenticated"),
                "Sender Type": item.get("sender_type"),
                "Sender Pattern": item.get("sender_pattern"),
                "Sender Pattern Type": item.get("sender_pattern_type"),
                "Sender Ip Type": item.get("sender_ip_type"),
                "Sender Ip Group": item.get("sender_ip_group"),
                "Sender Ip Mask": item.get("sender_ip_mask"),
                "Sender Geo IP Group": item.get("sender_geoip_group"),
                "Recipient Pattern Type": item.get("recipient_pattern_type"),
                "Recipient Pattern Regex": item.get("recipient_pattern_regex") or item.get("recipient_pattern_regexp"),
                "Anti Spam": item.get("antispam"),
                "Content": item.get("content"),
                "PKI Auth": item.get("pkiauth"),
                "Direction": item.get("direction"),
                "Antivirus": item.get("antivirus"),
                "Resource Profile": item.get("misc"),
                "Group State": item.get("groupstate"),
                "Auth State": item.get("authstate"),
                "Alias State": item.get("alias_state"),
                "Routing State": item.get("routing_state"),
                "Address Map State": item.get("address_map_state"),
                "Cache State": item.get("cache_state"),
                "Country": item.get("country"),
                "Domain Name": item.get("domain"),
                "CA Certificate": item.get("ca_certificate"),
                "Subject": item.get("subject"),
                "LDAP Profile": item.get("ldapprofile"),
                "LDAP Query": item.get("ldapquery"),
                "OCSP verify": item.get("ocspverify"),
                "OCSP URL": item.get("ocspurl"),
                "SMTP Certificate": item.get("smtp_certificate"),
                "SMTP Certificate Direction": item.get("smtp_certificate_direction"),
                "SMTP Greeting Name": item.get("smtp_greeting_reply_name"),
                "Auth Port": item.get("authport"),
                "Access Override Vendor": item.get("access_override_vendor"),
                "Domain Override Vendor": item.get("domain_override_vendor"),
                "Group Name": item.get("group_name"),
            }
        )
    # Add the group name argument to the output for group commands
    if group_name := command_args.get("group_name"):
        new_output = {"mkey": group_name, "Member": output}
        return output_table, [new_output]

    return output_table, output


def handle_recipient_policy_command_args(args: dict[str, Any]) -> dict[str, Any]:
    """
    Get and convert recipient policy command arguments.

    Args:
        args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: Updated command arguments.
    """
    return remove_empty_elements(
        {
            "recipient_policy_id": args.get("recipient_policy_id"),
            "status": BOOLEAN_MAPPER.get(args.get("status", "")),
            "comment": args.get("comment"),
            "direction": RP_DIRECTION_MAPPER.get(args.get("type", "")),
            "sender_type": RP_PATTERN_TYPE_MAPPER.get(args.get("sender_type", "")),
            "sender_pattern": args.get("sender_pattern"),
            "sender_ldap_profile": args.get("sender_ldap_profile"),
            "sender_email_address_group": args.get("sender_email_address_group"),
            "recipient_email_address_group": args.get("recipient_email_address_group"),
            "recipient_type": RP_PATTERN_TYPE_MAPPER.get(args.get("recipient_type", "")),
            "recipient_pattern": args.get("recipient_pattern"),
            "recipient_ldap_profile": args.get("recipient_ldap_profile"),
            "antispam_profile": args.get("antispam_profile"),
            "antivirus_profile": args.get("antivirus_profile"),
            "content_profile": args.get("content_profile"),
            "resource_profile": args.get("resource_profile"),
            "auth_profile": args.get("auth_profile"),
            "pki_profile": args.get("pki_profile"),
            "auth_type": RP_AUTH_MAPPER.get(args.get("auth_type", "")),
            "use_smtp_auth": BOOLEAN_MAPPER.get(args.get("use_smtp_auth", "")),
            "smtp_different": BOOLEAN_MAPPER.get(args.get("smtp_different", "")),
            "smtp_diff_identity_ldap": BOOLEAN_MAPPER.get(args.get("smtp_diff_identity_ldap", "")),
            "smtp_diff_identity_ldap_profile": args.get("smtp_diff_identity_ldap_profile"),
            "enable_pki": BOOLEAN_MAPPER.get(args.get("enable_pki", "")),
            "certificate_validation": BOOLEAN_MAPPER.get(args.get("certificate_validation", "")),
        }
    )


def handle_ip_policy_command_args(args: dict[str, Any]) -> dict[str, Any]:
    """
    Get and convert IP policy command arguments.

    Args:
        args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: Updated command arguments.
    """
    return remove_empty_elements(
        {
            "ip_policy_id": args.get("ip_policy_id"),
            "status": BOOLEAN_MAPPER.get(args.get("status", "")),
            "comment": args.get("comment"),
            "source": args.get("source"),
            "destination_type": DESTINATION_MAPPER.get(args.get("destination_type", "")),
            "destination": args.get("destination", ""),
            "action": IP_ACTION_MAPPER.get(args.get("action", "")),
            "source_type": AC_SENDER_IP_TYPE_MAPPER.get(args.get("source_type", "")),
            "ip_pool_profile": args.get("ip_pool_profile"),
            "antispam_profile": args.get("antispam_profile"),
            "antivirus_profile": args.get("antivirus_profile"),
            "content_profile": args.get("content_profile"),
            "session_profile": args.get("session_profile"),
            "auth_profile": args.get("auth_profile"),
            "auth_type": RP_AUTH_MAPPER.get(args.get("auth_type", "")),
            "use_smtp_auth": BOOLEAN_MAPPER.get(args.get("use_smtp_auth", "")),
            "smtp_different": BOOLEAN_MAPPER.get(args.get("smtp_different", "")),
            "smtp_diff_identity_ldap": BOOLEAN_MAPPER.get(args.get("smtp_diff_identity_ldap", "")),
            "smtp_diff_identity_ldap_profile": args.get("smtp_diff_identity_ldap_profile"),
            "exclusive": BOOLEAN_MAPPER.get(args.get("exclusive", "")),
        }
    )


def handle_access_control_command_args(args: dict[str, Any]) -> dict[str, Any]:
    """
    Get and convert access control command arguments.

    Args:
        args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: Updated command arguments.
    """
    return remove_empty_elements(
        {
            "access_control_id": args.get("access_control_id"),
            "status": BOOLEAN_MAPPER.get(args.get("status", "")),
            "sender_type": AC_PATTERN_TYPE_MAPPER.get(args.get("sender_type", "")),
            "sender": args.get("sender"),
            "recipient_type": AC_PATTERN_TYPE_MAPPER.get(args.get("recipient_type", "")),
            "recipient": args.get("recipient"),
            "sender_ldap_profile": args.get("sender_ldap_profile"),
            "recipient_ldap_profile": args.get("recipient_ldap_profile"),
            "source_type": AC_SENDER_IP_TYPE_MAPPER.get(args.get("source_type", "")),
            "source": args.get("source"),
            "reverse_dns_pattern": args.get("reverse_dns_pattern"),
            "reverse_dns_pattern_regex": BOOLEAN_MAPPER.get(args.get("reverse_dns_pattern_regex", "")),
            "authentication_status": AC_AUTH_MAPPER.get(args.get("authentication_status", "")),
            "tls_profile": args.get("tls_profile"),
            "action": AC_ACTION_MAPPER.get(args.get("action", "")),
            "comment": args.get("comment"),
        }
    )


def handle_delete_command_args(args: dict[str, Any]) -> dict[str, Any]:
    """
    Get and convert delete command arguments.

    Args:
        args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: Updated command arguments.
    """
    return remove_empty_elements(
        {
            "name": args.get("name"),
            "group_name": args.get("group_name"),
            "ip": args.get("ip"),
            "email": args.get("email"),
            "values": args.get("values"),
            "list_type": args.get("list_type"),
            "access_control_id": args.get("access_control_id"),
            "policy_id": args.get("policy_id"),
            "recipient_policy_id": args.get("recipient_policy_id"),
        }
    )


def handle_list_command_args(args: dict[str, Any]) -> dict[str, Any]:
    """
    Get and convert list command arguments.

    Args:
        args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: Updated command arguments.
    """
    return remove_empty_elements(
        {
            "group_name": args.get("group_name"),
            "ip": args.get("ip"),
            "access_control_id": args.get("access_control_id"),
            "policy_id": args.get("policy_id"),
            "recipient_policy_id": args.get("recipient_policy_id"),
            "email": args.get("email"),
            "name": args.get("name"),
            "list_type": args.get("list_type"),
        }
    )


def modify_group_member_args_before_replace(group_members: list[str]) -> dict[str, Any]:
    """
    Get the IP/email group members and modify it for the API.

    Args:
        group_members (list[str]): The IP/email group members.

    Returns:
        dict[str, Any]: The updated payload for the API request.
    """
    updated_group_members_payload: dict[str, Any] = {f"mkey_{i}": group_member for i, group_member in enumerate(group_members)}
    # Get the total amount of items to replaces for the API call.
    updated_group_members_payload["reqObjCount"] = len(updated_group_members_payload)
    return updated_group_members_payload


def update_group_member_args(command_args: dict[str, Any]) -> dict[str, Any]:
    """
    Update the IP/email group members arguments.
    Convert CIDR to IP in case IP is provided.

    Args:
        command_args (dict[str, Any]): The command arguments.

    Returns:
        dict[str, Any]: The updated request arguments.
    """
    group_member_args = copy.deepcopy(command_args)

    if ips := group_member_args.get("ips"):
        updated_ips = [convert_cidr_to_ip_range(item) for item in ips]
        group_member_args["ips"] = modify_group_member_args_before_replace(group_members=updated_ips)

    if emails := group_member_args.get("emails"):
        group_member_args["emails"] = modify_group_member_args_before_replace(group_members=emails)

    if ip := group_member_args.get("ip"):
        group_member_args["ip"] = convert_cidr_to_ip_range(ip)
    return group_member_args


def validate_value_exist_before_delete(client: Client, command_args: dict[str, Any], command_name: str):
    """
    Validate item exist before delete it.

    Args:
        client (Client): API client.
        command_args (dict[str, Any]): The command args.
        command_name (str): The command name.

    Raises:
        ValueError: In case the item doesn't exist.
    """
    # Get the 'get' request function by command name.
    get_request: Callable = get_command_request(command_name=command_name.replace("delete", "list"), client=client)
    # Remove the 'values' argument in case exist before calling GET
    values = command_args.pop("values", None)

    # Make a GET request to insure the item is exist before delete
    try:
        get_request(**command_args)
    except DemistoException as exc:
        raise ValueError(f"Item doesn't exist. {exc}")

    # Reset the 'values' argument in case exist
    if values:
        command_args["values"] = values


def get_command_request(command_name: str, client: Client) -> Callable[..., Any]:
    """
    Get request function by command name.

    Args:
        command_name (str): The command name.
        client (Client): API client.

    Returns:
        Callable[..., Any]: The request function.
    """
    request_by_command_name = {
        "fortimail-system-safe-block-add": client.add_system_safe_block,
        "fortimail-ip-policy-create": client.create_ip_policy,
        "fortimail-ip-policy-update": client.update_ip_policy,
        "fortimail-access-control-create": client.create_access_control,
        "fortimail-access-control-update": client.update_access_control,
        "fortimail-recipient-policy-create": client.create_recipient_policy,
        "fortimail-recipient-policy-update": client.update_recipient_policy,
        "fortimail-pki-user-list": client.list_pki_user,
        "fortimail-recipient-policy-list": client.list_recipient_policy,
        "fortimail-tls-profile-list": client.list_tls_profile,
        "fortimail-ldap-group-list": client.list_ldap_group,
        "fortimail-geoip-group-list": client.list_geoip_group,
        "fortimail-antispam-profile-list": client.list_antispam_profile,
        "fortimail-antivirus-profile-list": client.list_antivirus_profile,
        "fortimail-content-profile-list": client.list_content_profile,
        "fortimail-ip-pool-list": client.list_ip_pool,
        "fortimail-session-profile-list": client.list_session_profile,
        "fortimail-access-control-list": client.list_access_control,
        "fortimail-ip-policy-list": client.list_ip_policy,
        "fortimail-email-group-member-list": client.list_email_group_member,
        "fortimail-system-safe-block-list": client.list_system_safe_block,
        "fortimail-ip-group-list": client.list_ip_group,
        "fortimail-ip-group-member-list": client.list_ip_group_member,
        "fortimail-email-group-list": client.list_email_group,
        "fortimail-smtp-auth-profile-list": client.list_smtp_auth_profile,
        "fortimail-resource-profile-list": client.list_resource_profile,
        "fortimail-imap-auth-profile-list": client.list_imap_auth_profile,
        "fortimail-radius-auth-profile-list": client.list_radius_auth_profile,
        "fortimail-pop3-auth-profile-list": client.list_pop3_auth_profile,
        "fortimail-email-group-create": client.create_email_group,
        "fortimail-ip-group-create": client.create_ip_group,
        "fortimail-email-group-update": client.update_email_group,
        "fortimail-ip-group-update": client.update_ip_group,
        "fortimail-ip-group-delete": client.delete_ip_group,
        "fortimail-ip-group-member-delete": client.delete_ip_group_member,
        "fortimail-email-group-delete": client.delete_email_group,
        "fortimail-email-group-member-delete": client.delete_email_group_member,
        "fortimail-system-safe-block-delete": client.delete_system_safe_block,
        "fortimail-ip-policy-delete": client.delete_ip_policy,
        "fortimail-access-control-delete": client.delete_access_control,
        "fortimail-recipient-policy-delete": client.delete_recipient_policy,
        "fortimail-ip-policy-move": client.move_ip_policy,
        "fortimail-access-control-move": client.move_access_control,
        "fortimail-recipient-policy-move": client.move_recipient_policy,
        "fortimail-ip-group-member-add": client.add_ip_group_member,
        "fortimail-ip-group-member-replace": client.replace_ip_group_member,
        "fortimail-email-group-member-add": client.add_email_group_member,
        "fortimail-email-group-member-replace": client.replace_email_group_member,
    }
    return request_by_command_name[command_name]


def get_command_entity(command_name: str) -> tuple[str, str]:
    """
    Return the command request name, title, and output prefix name by command name.

    Args:
        command_name (str): The command name.
    Returns:
        tuple[str, str, str]: The command request name, title, and output prefix.
    """
    command_name_parts = command_name.split("-")
    command_operator = command_name_parts[-1]
    command_entity = "_".join(command_name_parts[1:-1])
    command_entity_title = command_entity.replace("_", " ").title()
    command_outputs_prefix = OUTPUT_PREFIX_MAPPER[command_entity]

    if command_operator == "add":
        command_entity_title = f"{command_entity_title} {command_operator}ed successfully"
    elif command_operator != "list":
        command_entity_title = f"{command_entity_title} {command_operator}d successfully"

    return command_entity_title, command_outputs_prefix


def main() -> None:
    params: Dict[str, Any] = demisto.params()
    args: Dict[str, Any] = demisto.args()

    url: str = params.get("url", "")
    user_name = params["credentials"]["identifier"]
    password = params["credentials"]["password"]
    verify_certificate: bool = not params.get("insecure", False)
    proxy: bool = params.get("proxy", False)

    command = demisto.command()
    args["command_name"] = command
    demisto.debug(f"Command being called is {command}")

    try:
        client: Client = Client(
            server_url=url,
            user_name=user_name,
            password=password,
            verify=verify_certificate,
            proxy=proxy,
        )

        commands = {
            "fortimail-system-safe-block-add": add_system_safe_block_command,
            "fortimail-ip-policy-create": ip_policy_create_update_command,
            "fortimail-ip-policy-update": ip_policy_create_update_command,
            "fortimail-access-control-create": access_control_create_update_command,
            "fortimail-access-control-update": access_control_create_update_command,
            "fortimail-recipient-policy-create": recipient_policy_create_update_command,
            "fortimail-recipient-policy-update": recipient_policy_create_update_command,
        }

        if command == "test-module":
            return_results(test_module(client))
        elif command in [
            "fortimail-pki-user-list",
            "fortimail-recipient-policy-list",
            "fortimail-tls-profile-list",
            "fortimail-ldap-group-list",
            "fortimail-geoip-group-list",
            "fortimail-antispam-profile-list",
            "fortimail-antivirus-profile-list",
            "fortimail-content-profile-list",
            "fortimail-ip-pool-list",
            "fortimail-session-profile-list",
            "fortimail-access-control-list",
            "fortimail-ip-policy-list",
            "fortimail-email-group-member-list",
            "fortimail-system-safe-block-list",
            "fortimail-ip-group-list",
            "fortimail-ip-group-member-list",
            "fortimail-email-group-list",
            "fortimail-smtp-auth-profile-list",
            "fortimail-resource-profile-list",
            "fortimail-imap-auth-profile-list",
            "fortimail-radius-auth-profile-list",
            "fortimail-pop3-auth-profile-list",
        ]:
            return_results(list_command(client, args))
        elif command in [
            "fortimail-email-group-create",
            "fortimail-ip-group-create",
            "fortimail-email-group-update",
            "fortimail-ip-group-update",
        ]:
            return_results(group_create_update_command(client, args))
        elif command in [
            "fortimail-ip-group-delete",
            "fortimail-ip-group-member-delete",
            "fortimail-email-group-delete",
            "fortimail-email-group-member-delete",
            "fortimail-system-safe-block-delete",
            "fortimail-ip-policy-delete",
            "fortimail-access-control-delete",
            "fortimail-recipient-policy-delete",
        ]:
            return_results(delete_command(client, args))
        elif command in [
            "fortimail-ip-policy-move",
            "fortimail-access-control-move",
            "fortimail-recipient-policy-move",
        ]:
            return_results(move_command(client, args))
        elif command in [
            "fortimail-ip-group-member-add",
            "fortimail-ip-group-member-replace",
            "fortimail-email-group-member-add",
            "fortimail-email-group-member-replace",
        ]:
            return_results(group_member_add_replace_command(client, args))
        elif command in commands:
            return_results(commands[command](client, args))
        else:
            raise NotImplementedError(f"{command} command is not implemented.")

    except Exception as e:
        return_error(str(e))


if __name__ in ["__main__", "builtin", "builtins"]:
    main()