# Send Mail

This function block lets you send emails using Gmail SMTP. It is intended for sending plain-text messages and optional file attachments from workflows. The block expects the sender account to be enabled for Gmail API / SMTP access.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Subject` - The email subject text (string).

`Content` - The body content of the email (string).

`Sender Address` - The Gmail address that will send the message (string). Must be configured for SMTP/API use.

`Mail API Password` - The password or API key used for authenticating the sender address (string).

`Receiver Address` - The destination email address (string).

`Attachment File Path` - Optional full file path to attach to the email (string). Leave empty if no attachment.

`Trigger` - Boolean signal that initiates sending when active.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Success` - Boolean indicating whether the send action succeeded.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Send` - There is no separate send button; sending is initiated by providing an active `Trigger` to the block. Configure message fields via inputs.

## ⚙️ Running Mechanism <a href="#how-it-runs" id="how-it-runs"></a>

* The block waits for inputs to be provided and for the `Trigger` to become active.
* When triggered, it attempts to authenticate the provided sender account and send the message to the receiver.
* Attachments are included when a valid file path is provided.
* The block returns `Success` True on successful send, False otherwise.
* If authentication or delivery fails due to a transient issue, the block will attempt to reconnect and resend automatically.

## ✨ Features <a href="#features" id="features"></a>

* Sends plain-text emails via Gmail SMTP.
* Supports a single file attachment by file path.
* Uses a cached session to avoid re-authenticating on every trigger when possible.
* Automatic reconnect and retry on transient session issues.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Provide the sender credentials and enable SMTP/API access on the Gmail account.
2. Fill `Subject`, `Content`, `Sender Address`, `Mail API Password`, and `Receiver Address` inputs.
3. Optionally provide a file path to `Attachment File Path` for attachments.
4. Activate the `Trigger` input to send the message.
5. Monitor the `Success` output to confirm delivery.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* To capture and attach an image from a camera, combine this block with `Camera USB` or `Camera IP (ONVIF)` and save the frame using `Image Write` or `Image Logger`. Provide the saved path to `Attachment File Path`.
* If you want to send notifications only once when an event happens, use `Rising Edge` or `Logic Input` to create a one-time `Trigger` pulse.
* Build message text dynamically using `String Merge` or prepare structured logs with `Data to JSON` before sending.
* When emailing multiple images, use `Multi Image Write` to store images then attach from file paths (one at a time as supported).
* For sending event snapshots as part of analysis pipelines, combine with analysis blocks such as `Find Object` or `Mask Detection` to decide when to trigger the email.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Authentication fails: verify that the `Sender Address` is enabled for SMTP/API access and that the `Mail API Password` is correct. Check Gmail account security settings.
* Attachment not sent: ensure the path in `Attachment File Path` points to an existing file and is accessible from the runtime environment.
* Email not delivered: check receiver address spelling and spam/junk folders. Network restrictions or firewalls may block SMTP ports.
* Trigger ignored: confirm the `Trigger` input receives an explicit True value (or a rising edge) at runtime.
* Session expired: the block will attempt to reconnect automatically, but if persistent failures occur, re-check credentials and network connectivity.

## 🔒 Privacy & Security <a href="#privacy-and-security" id="privacy-and-security"></a>

* Do not store sensitive passwords in shared projects. Use secure secrets handling where possible.
* Limit the sender account privileges and enable appropriate security measures on the Gmail account used for sending.


---

# 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://docs.augelab.com/function-blocks/input-output/communication/send-mail.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.
