Navigation
  • Rules >
  • Mailgun Service Rules

Mailgun Service Rules

To use the Mailgun Service, you must specify rules to enable its actions. The rules must evaluate to true for the action to be enabled. An empty document ({}) always evaluates to true.

Specify a Rule

  1. Select the action for which the rule applies.

    The Mailgun service supports one action: send.

  2. Specify the rule in valid JSON that evaluates to a boolean. You can specify MongoDB query expression operators with the exception of the $text and geospatial operators:

    {
      <field1>: <value1|expression1>,
      <field2>: <value2|expression2>,
      ...
    }
    

    You can specify rules based on an argument to the action. For details and examples, see SES Service Arguments.

Mailgun Service Arguments

To specify a rule based on arguments:

{
  "%%args.<argument1>": <value1|expression1>,
  "%%args.<argument2>": <value1|expression2>,
  ...
}

Or, you can omit the %%args prefix if you do not specify any expansion prefixes for the fields.

{
  "<argument1>": <value1|expression1>,
  "<argument2>": <value1|expression2>,
  ...
}

However, you cannot mix arguments with prefixes and arguments without prefixes in the same rule. For example, the following rule is invalid:

{
  "%%args.to": "text@example.com",
  "from": "someone@example.com",
  ...
}

You can use the following arguments in Mailgun service rules.

to

The to argument is a string that corresponds to the destination email address.

Note

The address specified must appear in the list of authenticated recipients for your Mailgun account.

from

The from argument is a string that corresponds to the originating email address.

subject

The subject argument is a string that corresponds to the subject of the message.

text

The text argument is a string that corresponds to the body of the message.

Example

Actions When
send
{
  "from" : "someone@example.com",
  "to": { "%in": "%%values.opt-ins" }
}

The rule ensures that applications can only perform a send action when:

  • from is someone@example.com, and
  • to is an email listed in the opt-ins, where opt-ins is a user-defined constant. For more information in defining constants, see Values.