<commit_before>[[actions-email]]
=== Email Action

Use the `email` action to send email notifications. To send email, you must
<<configuring-email, configure at least one email account>> in
`elasticsearch.yml`.

Email notifications can be plain text or styled using HTML. You can include
information from the watch execution payload using <<templates, templates>>
and attach the entire watch payload to the message.

See <<email-action-attributes>> for the supported attributes. Any attributes that
are missing from the email action definition are looked up in the email
account configuration. The required attributes must either be set in the email
action definition or the account's `email_defaults`.

[[configuring-email-actions]]
==== Configuring Email Actions

You configure email actions in the `actions` array. Action-specific attributes
are specified using the `email` keyword.

For example, the following email action uses a template to include data from
the watch payload in the email body:

[source,js]
--------------------------------------------------
"actions" : {
  "send_email" : { <1>
    "email" : { <2>
      "to" : "<username>@<domainname>", <3>
      "subject" : "Watcher Notification", <4>
      "body" : "{{ctx.payload.hits.total}} error logs found" <5>
    }
  }
}
--------------------------------------------------
<1> The id of the action.
<2> The action type is set to `email`.
<3> One or more addresses to send the email to. Must be specified in the
    action definition or in the email account configuration.
<4> The subject of the email can contain static text and Mustache <<templates,
    templates>>.
<5> The body of the email can contain static text and Mustache <<templates,
     templates>>. Must be specified in the action definition or in the email
     account configuration.

[[configuring-email-attachments]]
==== Configuring Email Attachments

You can attach the execution context payload or data from an any HTTP service to
the email notification. There is no limit on the number of attachments you can
configure.

To configure attachments, specify a name for the attached file and the type of
attachment: `data`, `http` or `reporting`. The `data` attachment type attaches the execution
context payload to the email message. The `http` attachment type enables
you to issue an HTTP request and attach the response to the email message. When
configuring the `http` attachment type, you must specify the request URL. The
`reporting` attachment type is a special type to include PDF rendered dashboards
from kibana. This type is consistently polling the kibana app if the dashboard
rendering is done, preventing long running HTTP connections, that are potentially
killed by firewalls or load balancers inbetween.

[source,js]
--------------------------------------------------
"actions" : {
  "email_admin" : {
    "email": {
      "to": "<NAME> <<EMAIL>>",
      "attachments" : {
        "my_image.png" : { <1>
          "http" : { <2>
            "content_type" : "image.png",
            "request" : {
              "url": "http://example.org/foo/my-image.png" <3>
            }
          }
        },
        "dashboard.pdf" : {
          "reporting" : {
            "url": "http://example.org:5601/api/reporting/generate/dashboard/Error-Monitoring"
          }
        },
        "data.yml" : {
          "data" : {
            "format" : "yaml" <4>
          }
        }
      }
    }
  }
}
--------------------------------------------------
<1> The ID of the attachment, which is used as the file name in the email
    attachment.
<2> The type of the attachment and its specific configuration.
<3> The URL from which to retrieve the attachment.
<4> Data attachments default to JSON if you don't specify the format.

.`http` attachment type attributes
[options="header"]
|=====
| Name            | Description
| `content_type`  | Sets the content type for the email attachment. By default,
                    the content type is extracted from the response sent by the
                    HTTP service. You can explicitly specify the content type to
                    ensure that the type is set correctly in the email in case
                    the response does not specify the content type or it's specified
                    incorrectly. Optional.
| `inline`        | Configures as an attachment to sent with disposition `inline`. This
                    allows the use of embedded images in HTML bodies, which are displayed
                    in certain email clients. Optional. Defaults to `false`.
| `request`       | Contains the HTTP request attributes. At a minimum, you must
                    specify the `url` attribute to configure the host and path to
                    the service endpoint. See <<webhook-action-attributes>> for
                    the full list of HTTP request attributes. Required.
|======

.`data` attachment type attributes
[options="header"]
|=====
| Name        | Description
| `format`    | Attaches the watch data, equivalent to specifying `attach_data`
                in the watch configuration. Possible values are `json` or `yaml`.
                Defaults to `json` if not specified.
|======


.`reporting` attachment type attributes
[options="header"]
|=====
| Name            | Description
| `url`           | The URL to trigger the dashboard creation
| `inline`        | Configures as an attachment to sent with disposition `inline`. This
                    allows the use of embedded images in HTML bodies, which are displayed
                    in certain email clients. Optional. Defaults to `false`.
| `retries`       | The reporting attachment type tries to poll regularly to receive the
                    created PDF. This configures the number of retries. Defaults to `40`.
                    The setting `xpack.notification.reporting.retries` can be configured
                    globally to change the default.
| `interval`      | The time to wait between two polling tries. Defaults to `15s` (this
                    means, by default watcher tries to download a dashboard for 10 minutes,
                    forty times fifteen seconds). The setting `xpack.notification.reporting.interval`
                    can be configured globally to change the default.
| `request.auth`  | Additional auth configuration for the request
| `request.proxy` | Additional proxy configuration for the request
|======


[[email-action-reports]]
===== Attaching Reports to an Email

You can use the `http` attachment type in an `email` action to automatically<commit_msg>[DOCS] Fixed typo in Watcher email actions (elastic/x-pack-elasticsearch#2829)<commit_after>[[actions-email]]
=== Email Action

Use the `email` action to send email notifications. To send email, you must
<<configuring-email, configure at least one email account>> in
`elasticsearch.yml`.

Email notifications can be plain text or styled using HTML. You can include
information from the watch execution payload using <<templates, templates>>
and attach the entire watch payload to the message.

See <<email-action-attributes>> for the supported attributes. Any attributes that
are missing from the email action definition are looked up in the email
account configuration. The required attributes must either be set in the email
action definition or the account's `email_defaults`.

[[configuring-email-actions]]
==== Configuring Email Actions

You configure email actions in the `actions` array. Action-specific attributes
are specified using the `email` keyword.

For example, the following email action uses a template to include data from
the watch payload in the email body:

[source,js]
--------------------------------------------------
"actions" : {
  "send_email" : { <1>
    "email" : { <2>
      "to" : "<username>@<domainname>", <3>
      "subject" : "Watcher Notification", <4>
      "body" : "{{ctx.payload.hits.total}} error logs found" <5>
    }
  }
}
--------------------------------------------------
<1> The id of the action.
<2> The action type is set to `email`.
<3> One or more addresses to send the email to. Must be specified in the
    action definition or in the email account configuration.
<4> The subject of the email can contain static text and Mustache <<templates,
    templates>>.
<5> The body of the email can contain static text and Mustache <<templates,
     templates>>. Must be specified in the action definition or in the email
     account configuration.

[[configuring-email-attachments]]
==== Configuring Email Attachments

You can attach the execution context payload or data from an any HTTP service to
the email notification. There is no limit on the number of attachments you can
configure.

To configure attachments, specify a name for the attached file and the type of
attachment: `data`, `http` or `reporting`. The `data` attachment type attaches the execution
context payload to the email message. The `http` attachment type enables
you to issue an HTTP request and attach the response to the email message. When
configuring the `http` attachment type, you must specify the request URL. The
`reporting` attachment type is a special type to include PDF rendered dashboards
from kibana. This type is consistently polling the kibana app if the dashboard
rendering is done, preventing long running HTTP connections, that are potentially
killed by firewalls or load balancers inbetween.

[source,js]
--------------------------------------------------
"actions" : {
  "email_admin" : {
    "email": {
      "to": "<NAME> <<EMAIL>>",
      "attachments" : {
        "my_image.png" : { <1>
          "http" : { <2>
            "content_type" : "image.png",
            "request" : {
              "url": "http://example.org/foo/my-image.png" <3>
            }
          }
        },
        "dashboard.pdf" : {
          "reporting" : {
            "url": "http://example.org:5601/api/reporting/generate/dashboard/Error-Monitoring"
          }
        },
        "data.yml" : {
          "data" : {
            "format" : "yaml" <4>
          }
        }
      }
    }
  }
}
--------------------------------------------------
<1> The ID of the attachment, which is used as the file name in the email
    attachment.
<2> The type of the attachment and its specific configuration.
<3> The URL from which to retrieve the attachment.
<4> Data attachments default to JSON if you don't specify the format.

.`http` attachment type attributes
[options="header"]
|=====
| Name            | Description
| `content_type`  | Sets the content type for the email attachment. By default,
                    the content type is extracted from the response sent by the
                    HTTP service. You can explicitly specify the content type to
                    ensure that the type is set correctly in the email in case
                    the response does not specify the content type or it's specified
                    incorrectly. Optional.
| `inline`        | Configures as an attachment to sent with disposition `inline`. This
                    allows the use of embedded images in HTML bodies, which are displayed
                    in certain email clients. Optional. Defaults to `false`.
| `request`       | Contains the HTTP request attributes. At a minimum, you must
                    specify the `url` attribute to configure the host and path to
                    the service endpoint. See <<webhook-action-attributes>> for
                    the full list of HTTP request attributes. Required.
|======

.`data` attachment type attributes
[options="header"]
|=====
| Name        | Description
| `format`    | Attaches the watch data, equivalent to specifying `attach_data`
                in the watch configuration. Possible values are `json` or `yaml`.
                Defaults to `json` if not specified.
|======


.`reporting` attachment type attributes
[options="header"]
|=====
| Name            | Description
| `url`           | The URL to trigger the dashboard creation
| `inline`        | Configures as an attachment to sent with disposition `inline`. This
                    allows the use of embedded images in HTML bodies, which are displayed
                    in certain email clients. Optional. Defaults to `false`.
| `retries`       | The reporting attachment type tries to poll regularly to receive the
                    created PDF. This configures the number of retries. Defaults to `40`.
                    The setting `xpack.notification.reporting.retries` can be configured
                    globally to change the default.
| `interval`      | The time to wait between two polling tries. Defaults to `15s` (this
                    means, by default watcher tries to download a dashboard for 10 minutes,
                    forty times fifteen seconds). The setting `xpack.notification.reporting.interval`
                    can be configured globally to change the default.
| `request.auth`  | Additional auth configuration for the request
| `request.proxy` | Additional proxy configuration for the request
|======


[[email-action-reports]]
===== Attaching Reports to an Email

You can use the `reporting` attachment type in an `email` action to automatically
{'fraction_non_alphanumeric': 0.11023741115983668, 'fraction_numerical': 0.004536518977771057, 'mean_word_length': 2.4689221085759243, 'pattern_counts': {'":': 8, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6945018', 'n_tokens_mistral': 3231, 'n_tokens_neox': 3104, 'n_words': 1536}