////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
:documentationPath: /workflow/actions/
:language: en_US
:description: The Mail action sends a text or HTML email with optional file attachments.

= Mail

== Description

The Mail action sends a text or HTML email with optional file attachments.

This action can be used at the end of a workflow run to either announce a successful run or send a notifications about a failure in the workflow.

For example, it is not uncommon at the end of a successful load, to send an email to a distribution list announcing that the load was successful and include a log file.

If there are errors, an email can be sent to alert individuals on a distribution list.

The Mail action requires an SMTP server.

You can use authentication and security as part of the connection but you must have the SMTP credentials.

You can attach files to your email messages such as error logs and regular logs.

In addition, logs can be zipped into a single archive for convenience.

== Options

=== Addresses Tab

[options="header", width="90%", cols="1,3"]
|===
|Option|Description
|Action name|The name of the workflow action.
2+|Destination
|Destination Address|The destination for the email; you can specify multiple addresses if you separate them with a space.
|Cc|An identical copy of the message is also sent to all the addresses listed in the Cc: field.
To enter more than one address in the Cc: field, separate them with a space.
|BCc|Send to a recipient whose email address does not appear in the message
2+|Sender
|Sender name|Name of the person sending the email
|Sender address|Email address of the person sending the email
|Reply to|Email address of the person to which to send a reply
|Contact person|The name of the contact person to be placed in the email
|Contact phone|The contact telephone number to be placed in the email
|===

=== Server Tab

[options="header", width="90%", cols="1,3"]
|===
|Option|Description
2+|SMTP Server
|SMTP Server|The SMTP server address
|Port|The port on which the SMTP Server is running
2+|Authentication
|Use Authentication|Enable to use authentication to the SMTP Server
|Use XOAUTH2 |If checked XOAuth2 will be used to authenticate with the server.
|Authentication user|SMTP user account name
|Authentication password|SMTP user account password
|Use Secure Authentication?|Enable to use secure authentication
|Secure Connection Type|Select authentication type (SSL, TLS, TLS 1.2)
|===

=== Email Message Tab

[options="header", width="90%", cols="1,3"]
|===
|Option|Description
|Include date in message?|Enable to include the current date in the message
|Only send comment in mail body?|If not enabled the email will contain information about the workflow and its execution in addition to the comment
|Use HTML in mail body|The message is sent in HTML format
|Encoding|Select the character encoding type used for the HTML format
|Manage Priority a|Enable to set the priority and sensitivity of the message. Typically, failures might be sent with a higher priority than successes.
Note: The support of this flag is depending on the mail server.

* Priority: Low, Normal, or High
* Importance: Low, Normal, or High
* Sensitivity: Normal, Personal, Private, or Confidential

|Subject|Enter the subject of the mail into this field.
|Comment| Enter the comment within the body of the mail into this field.
|===

=== Attached Files Tab

[options="header", width="90%", cols="1,3"]
|===
|Option|Description
|Attach files to message?|Enable to attach a file to your email message
|Select file type a|The files to send are defined within the internal files result set.
Every file in this list is marked with a file type and you can select what type of file you want to send (see also the tips at the end of this document):

* General
* Log
* Error line
* Error
* Warning

|Zip files to single archive?|Enable to have attachments achived in a zip file
|Name of the zip archive|Define the filename of your zip archive
|Filename|Name of a single image file to add.
Note: This works only when Use HTML format is defined in the EMail Message tab.
|Content ID|Automatically entered
|Image|The full path to image (used when embedding multiple images) Click Edit to edit the path; click Delete to delete the path to the image
|Content ID|The image content ID (used when embedding multiple images) Click Edit to edit the content ID; click Delete to delete the Content ID
|===

== Tips

**How to attach a particular file to the e-mail**

You can attach "Result Files" of a particular type(s) to the e-mail, either individually or as a single ZIP archive by checking the option "Attach files to message" and selecting the types to attach under "Select the result files types to attach".
What is a Result File and how to create one?
Well, just about any file created during a pipeline may become a Result File, you only need to mark it as such.
There are several ways to do that:

1. When creating a file with a transform that supports it, allow it to mark the file as a Result File.
For example the "Text file output" transform has the check-box "Add filenames to result" on the File tab for that purpose.
The file type will be General.
2. Use the transform "Set files in result" from the workflow category to mark a file as a result file of a particular type.
This transforms expects the file name to be in a field (you can use e.g. "Generate Rows" in combination with "Add constants" to produce a row containing the file name).

**Attaching pipeline's log**

You can attach a log file with log of a pipeline run by the workflow prior to sending the mail as follows. This assumes the workflow consists of three actions: Start -> Pipeline -> Mail.

1. In the Pipeline workflow action's options, check "Specify logfile?" and enter a name and extension for the file.
You can also specify the desired log level.
2. In the Mail workflow action's options, check "Attach files to message" and select (at least) the file type "Log".
3. The next time the mail is send, it will have the pipeline's log attached. 