# Workflow gửi email

Smart Hosts require a command line script to send email, as they do not have a built-in mail client.  A gmail account must be created and associated with the host; this will be the account that emails will be sent from.

**Configuring Email on a Smart Host**

The following instructions are used to set up mail access using a gmail.com account. This script is specific to gmail.com and should not be used to setup email for other email services.

**NOTE**: The specific steps and menu selections described below are based on the Google®/gmail software/web UI active at the time of writing, and may be subject to change at any time with no notice to Savant.  If the steps below do not align with the options presented, note that the general requirements remain the same, and steps should be reasonably modified based on the current options presented to the user at the time.

1. On the SDE, launch Savant Application Manager (SAM).
2. Select the appropriate da Vinci release for the host and click Activate.
3. Open System Monitor from the right menu.
4. In an open System Scanner window, select the Savant Smart Host.
5. Click Terminal in the menu bar to open an ssh session with the selected host.
6. When prompted, enter the password for the host.
7. At the command prompt type:\
   savantSetGmailAccount
8. Follow the instructions that appear in the dialog box.

\
Gmail may block the login from the Smart Host initially.  Send a test email via the Host, either by completing the [workflow configuration](https://community.savant.com/Customers/articles/Support_Article/How-to-Send-an-Email-SMS-Text-Notification-from-a-Triggered-Workflow#WorkflowConfig) and running the workflow, or by executing the relevant command and arguments to send a test email directly from a terminal command prompt on the Host.  IF the test email has not been sent after several minutes, follow the steps below:

1. Log into the Gmail.com account being used to send the email.
2. Navigate to the **Security Settings** of the account.
3. Approve the "unknown device" that has recently attempted to access the gmail account (this is the Smart Host).
4. Also in the **Security Settings,** change **"Allow Less Secure Apps"**&#x74;o **ON.**

**NOTE**: Two-Factor authentication is not supported for use within the Savant System.\
&#x20;

**Creating an Email Workflow on a Smart Host**

1. Open a configuration in Blueprint and Generate Services.
2. In the open View Services window, select a room in the Services For drop-down list.
3. Under **General Programmable Services > Service Requests** for the selected room, create a workflow to send an email/text.\
   Example: SystemStartedEmailSend.\
   !\[Graphical user interface, application

   Description automatically generated]\(/files/-MlOrAx4zrJyH8yiK26o)
4. Double-click the created workflow to open Automator.
5. In the open Automator window, search for "Run".
6. Drag the **Run Shell Script** action into the workflow.
7. In the created **Run Shell Script** action, set Pass Input: as arguments.\
   !\[Graphical user interface, application

   Description automatically generated]\(/files/-MlOrAx5tIIMWNtAMNdw)
8. Enter the following into Run Shell Script action based on the Smart Host model being used.\
   &#x20;

**SVR-SMRTD-00 | SVR-SMRTD-10 Smart Host**\
echo "Your Message" | mail -s "Email Subject" <recipient@email.com> -- -f <senderAccount@gmail.com> -F "Name of Sender"

**SHC-2000-xx Smart Host | SHC-S2 Smart Host**\
echo "Your Message" | /usr/local/bin/rpm/savantMail -s "Email Subject" -r <recipient@email.com> -f <senderAccount@gmail.com> -F "Name of Sender"

**Substitute Field Values:**

| Your Message          | Example: “This is to inform that the Savant system for \[**Customer**] has been restarted and is back in operation.” Replace \[**Customer**] with the name of the customer.                                                                        |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Email Subject         | Example: \[**Customer**] **System Has Restarted**. Replace \[**Customer**] with the name of the customer.                                                                                                                                          |
| <recipient@email.com> | Email address of the recipient. See [Sending SMS Text Messages](https://community.savant.com/Customers/articles/Support_Article/How-to-Send-an-Email-SMS-Text-Notification-from-a-Triggered-Workflow#SendSMS) to send a text in place of an email. |
| senderAccount         | Account name that was setup on the host to send emails. Gmail accounts only.                                                                                                                                                                       |
| Name of Sender        | Name of as the sender in the email's **From**: section.                                                                                                                                                                                            |

1. Save the workflow.
2. Re-generate services, save the Blueprint configuration, and upload to the Host.

\| ![User-added image](/files/-MlOrAx6Zmzj--LyfTQM) | <p><strong>IMPORTANT NOTES!</strong></p><ul><li>A backslash is required before any special character inside the body or subject of the email. The backslash will not show in the message sent.<br><strong>Example</strong>: echo "System has Restarted!" | /usr/local/bin/rpm/savantMail -s "Email Subject" -r <recipient@email.com> -f <senderAccount@gmail.com> -F "Name of Sender"</li><li>In the event that the Host is unable to send a test email, log in to the Gmail account in use, and review the "<strong>Device Activity and Security Events</strong>" section of the <strong>Sign-In and Security</strong> settings page. The Savant Host may need to be allowed permission to access the account within this menu.</li></ul> |
\| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |


---

# 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.aicontrol.vn/savant-tips-and-tricks/untitled.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.
