# 4.6 SMTP Email Configuration

## 1. Overview

ZTrust uses an SMTP (Simple Mail Transfer Protocol) server to send **emails** such as:

1. Account verification emails
2. Password reset links
3. OTP codes
4. Admin notifications
5. Account Updates, etc

To enable this, you need to configure SMTP settings at the **realm level** in the ZTrust Admin Console.

## 2. Prerequisites

Before configuring, ensure you have:

* An **SMTP server** (e.g., Gmail)
* A valid **email account** with username & password
* SMTP **host**, **port**, and **security type** (TLS/SSL) details
* Proper **firewall rules** allowing outbound traffic on SMTP port ( 465)

## 3. Configuration via Admin Console

1. **Login** to the **ZTrust Admin Console**.

   <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2Ffzgi3ezDO3nxKzaO3eHk%2Fimage.png?alt=media&#x26;token=7f86e4fc-ce98-45b0-b4cb-e5c765bd8586" alt=""><figcaption><p>Fig 4.6.a: Master realm</p></figcaption></figure>
2. Click on **Manage Realms** in the sidebar to view the list of realms available in your **ZTrust**.

   <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2FR5paoDmI3LonMVmwm86T%2Fimage.png?alt=media&#x26;token=dc5e190d-425e-4417-a4b5-90bf65e44f4f" alt=""><figcaption><p>Fig 4.6.b: List of realm under manage realms</p></figcaption></figure>
3. From the list of realms, select the realm where you want to configure email.

   <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2Fm8rsWxdBeAgayHnNtpTX%2Fimage.png?alt=media&#x26;token=d6617d5a-6215-4003-951a-f05f8899bbd6" alt=""><figcaption><p>Fig 4.6.c: Demo realm welcome page</p></figcaption></figure>
4. In the left sidebar, under the **Configure** section, Navigate to **`Realm Settings → Email`**

   <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2FF4i2DpHUZnHsaNeTGsd1%2Fimage.png?alt=media&#x26;token=f614a35b-a417-4ced-8bb2-c9f27d82d88a" alt=""><figcaption><p>Fig 4.6.d: Email tab under realm settings tab</p></figcaption></figure>
5. Fill in the SMTP details:

   <table><thead><tr><th width="270.60546875">Field</th><th>Description</th></tr></thead><tbody><tr><td>From</td><td>Email address that appears in the "From" field of emails.</td></tr><tr><td>From Display Name</td><td>Name that will be displayed (e.g., "ZTrust Support").</td></tr><tr><td>Reply-To</td><td>(Optional) Email address for replies.</td></tr><tr><td>Host</td><td>SMTP server hostname (e.g., <code>smtp.gmail.com</code>).</td></tr><tr><td>Port</td><td>SMTP port ( 465).</td></tr><tr><td>Encryption</td><td>Choose <code>SSL</code></td></tr><tr><td>Username</td><td>SMTP account username (full email address for most providers).</td></tr><tr><td>Password</td><td>SMTP account password or app-specific password.</td></tr><tr><td>Encryption</td><td>select <strong>SSL</strong> (instead of None or TLS).</td></tr><tr><td>Authentication</td><td>Keep this option checked if your SMTP server requires login credentials (username &#x26; password) to send emails.</td></tr></tbody></table>
6. **Note**: The password here does not refer to your email login password. You need to generate an app password from your Gmail account. Follow the steps below to generate the **app password**.

   1. Log in to the email account for which you need to generate the app password, click on your **profile** icon, and select ***Manage your Google Account**.*

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2F4D0nmQ2mkHgPFMYgTtUT%2Fimage.png?alt=media&#x26;token=81ff448f-3e44-40d8-8fcf-ddaefe705ed7" alt="" width="328"><figcaption><p>Fig 4.6.e: Gmail account info</p></figcaption></figure>
   2. On the home page, use the search bar to type ***App Passwords*****.** From the dropdown suggestions, select ***App Passwords***.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2FMbzKWa5vR2S61LY9hAhL%2Fimage.png?alt=media&#x26;token=5a812d2c-67a1-4480-b39d-531777da5e2b" alt=""><figcaption><p>Fig 4.6.f: Search for App Passwords under home section</p></figcaption></figure>
   3. You will be redirected to the App Passwords page. Enter a name for the app, for example ***ZTrust***, and then click *Create*.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2F4Dr7QV6caHNGbtXt1z8f%2Fimage.png?alt=media&#x26;token=3e79332b-d6f1-4928-8204-2171915b4a8a" alt=""><figcaption><p>Fig 4.6.g: App password tab</p></figcaption></figure>
   4. A random app password will be generated.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2FTcJGXQEKqlaGMNCduoXY%2Fimage.png?alt=media&#x26;token=32e06019-6bf5-4686-8ed9-662876e7fb1e" alt=""><figcaption><p>Fig 4.6.h: Successfully app password created</p></figcaption></figure>
   5. Copy the generated password, then go to the **ZTrust** **Admin** **Console**. Open the realm where you want to configure SMTP and paste this password in the SMTP settings.
   6. Make sure you have configured the SMTP host, port, username, and password.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2F6nmvrSMJ2r1ZpFb3ni0P%2Fimage.png?alt=media&#x26;token=7e47babf-0497-4df8-9651-3a22f9f61537" alt=""><figcaption><p>Fig 4.6.i: Entered SMTP configuration</p></figcaption></figure>
   7. &#x20;Then save the configuration. You will see a success notification confirming that the update was successful.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2F3oOc3vBJACodn29gpFJo%2Fimage.png?alt=media&#x26;token=b64828ed-ba23-4d80-8999-35c2b5eb3f12" alt=""><figcaption><p>Fig 4.6.j: Saved SMTP configuration</p></figcaption></figure>
   8. Click on **Test Connection**. A confirmation email will be sent to your email address to verify that the SMTP configuration was successful.

      <figure><img src="https://1778922777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3EUK5AUZv0UVaI5S0CTM%2Fuploads%2Faob39thjTucxdiis4E2b%2Fimage.png?alt=media&#x26;token=da7cfebc-02cd-4e61-8c9b-fd999ae8e77f" alt=""><figcaption><p>Fig 4.6.k: Successfully connection established</p></figcaption></figure>
   9. You have now successfully configured SMTP email in **ZTrust** for the selected realm. If you create a new realm, follow the same steps to configure SMTP for that realm as well.

## 4. Troubleshooting

1. **Emails not being sent?**
   1. Check ZTrust logs (`docker logs ZTrust` or `ZTrust server logs` ).
   2. Verify SMTP credentials.
   3. Ensure firewall allows outbound SMTP ports.
2. **Authentication failed?**
   1. Check username/password.
   2. For Gmail use app password.
3. **SSL handshake errors?**
   1. Try switching between TLS/SSL.
   2. Ensure correct port is used.

You have successfully configured SMTP email in ZTrust Admin console for your selected realm. This enables ZTrust to send notification emails such as verification links, password resets, and account updates.

If you create additional realms, simply follow the same steps to configure SMTP for each realm.
