# Email Notifications

Stakeholders are interested in the progress of samples as they move through a workflow. E-mail alerts of events can provide them with real-time notifications.

Some possible uses of notifications include the following:

* Completion of a workflow for billing department
* Manager review requests
* Notice of new files added via the Collaborations Lablink Interface
* Updates on samples that are not following a standard path through a workflow

Clarity LIMS provides a simple way of accomplishing this using a combination of the Clarity LIMS API, EPP / automation triggers, and Simple Mail Transfer Protocol (SMTP).

### Solution <a href="#h_27cc8d06-643e-4064-9396-5b7dc897af93" id="h_27cc8d06-643e-4064-9396-5b7dc897af93"></a>

The **send\_email()** method uses the Python **smptlib** module to create a Simple Mail Transfer Protocol (SMPT) object to build and send the email. The attached script does the following:

1. Gathers relevant data from the Clarity LIMS API endpoints.
2. Generates an email body according to a template.
3. Calls the send\_email() function.

### Mail Server Configuration <a href="#h_47d7cbc0-8faa-4daa-b0c5-6551301a7035" id="h_47d7cbc0-8faa-4daa-b0c5-6551301a7035"></a>

Connect to Clarity SMTP with:

* host='localhost', port=25

Because of server restrictions, the script can send emails from only:

* <noreply.clarity@illumina.com>

### Automation Parameters <a href="#h_40755511-3a81-4d23-9bfb-a64d29cdc73d" id="h_40755511-3a81-4d23-9bfb-a64d29cdc73d"></a>

The automation / EPP command is configured to pass the following parameters:

<table data-header-hidden><thead><tr><th width="138"></th><th></th></tr></thead><tbody><tr><td>-u</td><td>The username of the current user (Required)</td></tr><tr><td>-p</td><td>The password of the current user (Required)</td></tr><tr><td>-s</td><td>The URI of the step that launches the script (Required)</td></tr></tbody></table>

Example command line:

{% code overflow="wrap" %}

```
python /opt/gls/clarity/customextensions/emails_from_Clarity.py -u {username} -p {password} -s {stepURI}
```

{% endcode %}

### User Interaction <a href="#h_90dba70a-9784-4fb1-87ea-af8a60e4894d" id="h_90dba70a-9784-4fb1-87ea-af8a60e4894d"></a>

* The script can be executed using a Clarity LIMS automation / EPP command, and trigged by one of the following methods:
  * Manually, via a button on the **Record Details** screen.
  * Automatically, at a step milestone (on entry to or exit from a screen).
* The script can also be triggered outside of a Clarity LIMS workflow, using a time-based job scheduler such as cron.

### Assumptions and Notes <a href="#h_42cecd45-d053-4a9d-bb6f-c148b7a3de46" id="h_42cecd45-d053-4a9d-bb6f-c148b7a3de46"></a>

* You are running a version of Python that is supported by Clarity LIMS, as documented in the *Clarity LIMS Technical Requirements*.
* The example code is provided for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.

### Attachments <a href="#h_d44aacee-22d6-47bb-aebd-ae83d707ddc6" id="h_d44aacee-22d6-47bb-aebd-ae83d707ddc6"></a>

emails\_from\_clarity.py:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-8fff741a81d2f8eae61f66cc14a99e237bfa3c4f%2Femails_from_clarity.py?alt=media&token=88d4833f-b34f-4416-a90e-74e336614863>" %}

emails\_attachmentPOC.py:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-0fddb4b2366dfc0dfab531efe567f037d4471340%2Femails_attachmentPOC.py?alt=media&token=865dc4e8-e43d-4c39-a59e-b7d2c7e7c034>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.connected.illumina.com/clarity-lims/api-and-database/api-docs/application-examples/page-15/email-notifications.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
