# Emails

## How to use

Your app will not use Bubble’s native “send email” functionality, but instead use our own SendGrid API workflow that generates a nicely-formatted HTML email from the system.

{% hint style="danger" %}
All of the below email flows will only work if you have [set up your SendGrid email ](https://docs.airdev.co/canvas/2.0.0-1/using-the-template/quickstart-guide#step-3-set-up-your-email)AND if you are not on a Hobby plan on the Bubble app (our email setup requires the use of API workflows, a paid Bubble feature).
{% endhint %}

![send\_email API workflow in Canvas: App Foundation template](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-L_iVFOOzjrt_liAx8my%2F-L_iIqsmVjSiIzYpC9pk%2FScreen%20Shot%202019-03-11%20at%2012.51.17%20PM.png?alt=media\&token=ed8f2656-dd1d-4c3d-bc8a-7d0b2ed35118)

To send a nicely-formatted HTML email:&#x20;

1. Go to the `Workflows` tab&#x20;
2. Select `Custom Events`
3. Select `Schedule API workflow`
4. Select `send_email` from the API workflow dropdown&#x20;
5. Set the scheduled date to `Current date/time`

![Setting up an email workflow](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ly_crm3mTmhRHhQ6tTv%2F-Ly_iZA9XF7xbFd0jjmw%2Fsend-email-api-wf.PNG?alt=media\&token=24df58c2-3b5b-46c3-aaee-95a25b297785)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-L_iVFOOzjrt_liAx8my%2F-L_iNhU_Xv6GU0WXYGJJ%2FScreen%20Shot%202019-03-11%20at%201.03.58%20PM.png?alt=media\&token=9c322676-c5ad-4f3a-99c1-236a386ee849)

Fill out the email content in the additional fields.

* **from\_name (required)** - Sender's name to display
* **from\_email (required)** - Sender's email. Note that if your SendGrid account was created after April 6, 2020, you'll need to use a verified sender's email address, or the message will not be sent and you will receive no notification of this (only an error in the Bubble app's server logs). Each SendGrid account can have up to 25 verified senders.
* **reply\_to\_email (optional)** - Sender's alternative email (if reply to email is different from from\_email)
* **to\_emails (required)** - Receiver's email (can be a comma separated list)
* **cc\_emails (optional)** - Carbon copy emails (can be a comma separated list)
* **bcc\_emails (optional)** - Blind carbon copy emails (can be a comma separated list)
* **subject (required)** - Email title / subject
* **body (required)** - Write `<br>` for a line break (since the parameter is a single line). Dynamic text (e.g., from a multiline input) will handle line breaks automatically.
  * Image in the body: `<img src='https:image’s url’ width=‘518’/>`
  * Link in the body:  `<a href="link url">Words to be hyperlinked</a>`
* **button\_text (optional)** - By default, there will be no button added to the email. However, if this field isn't empty, an action button will be added.
* **button\_link (optional)** - The link which the button is linked to
* **attachment (optional)** - If this is used, the file will be sent along with the email
* **button\_color (automatically populated)** - This is added from the field `Primary Color` on the Website object
* **signature (automatically populated)** - By default this will be `The [app name] team` but you can add a different text in this field to override it
* **logo** - By default, this is added from the field `Logo light` on the `Website` object, but you can also add a different logo in the API workflow parameter to override it.<br>

### How does this compare to Bubble's built-in email workflow?

You might be wondering why we would set up a workflow for something that Bubble already does.&#x20;

However, there are many advantages to setting up your app's emails through Sendgrid's API:

* Send email from your own domain name (e.g. <no-reply@airdev.co>)
  * Good for branding, and potentially with spam filters (depending on how many emails you send each month)
* Acess to email metrics or measure success of email marketing
  * With our SendGrid integration, you can [check the SendGrid dashboard](https://app.sendgrid.com/) of your account to see these metrics.
* Send attachments with emails
* Customize email's HTML design
  * Can make simple changes to the HTML
  * For complex customization, you need experience writing HTML for emails - this isn't possible without working with HTML code (outside the scope of this reference)

## Sign up flow - set up email verification

There are currently two sign up flows (modifiable by the App owner from the [General tab in the Admin portal](https://docs.airdev.co/canvas/v/2.0.0/using-the-template/reference/pages/owners-portal-page#admin-portal-overview)):&#x20;

* 2-step sign up (no email verification)
* 3-step sign up (with email verification)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3apYSiaGxdl74wZLH%2FScreen%20Shot%202019-10-25%20at%201.28.28%20PM.png?alt=media\&token=76b02143-475c-47a7-8ac5-a55a6ba38549)

### 2-step sign up (no email verification)

![Step 1 - Sign up with email and password](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3bbC6pKOVwT5bwJBT%2FScreen%20Shot%202019-10-25%20at%201.30.35%20PM.png?alt=media\&token=f0dae684-1d4a-405c-a583-9bc119ea059f)

![Step 2 - Add profile details](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3bojI1K-EcH87VQ1H%2FScreen%20Shot%202019-10-25%20at%201.32.24%20PM.png?alt=media\&token=fefbf014-e9d5-4736-9737-0ca522919fb6)

### 3-step sign up (email verification)

![Step 1 - Sign up with email and password](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3bbC6pKOVwT5bwJBT%2FScreen%20Shot%202019-10-25%20at%201.30.35%20PM.png?alt=media\&token=f0dae684-1d4a-405c-a583-9bc119ea059f)

![Step 2 - Add profile details](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3bojI1K-EcH87VQ1H%2FScreen%20Shot%202019-10-25%20at%201.32.24%20PM.png?alt=media\&token=fefbf014-e9d5-4736-9737-0ca522919fb6)

![Step 3 - The user will need to click the link in the email to verify their email address](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3dZPJ4R9Vgs0gDpaN%2FScreen%20Shot%202019-10-25%20at%201.40.12%20PM.png?alt=media\&token=5cc7b0c0-6708-4555-b42a-d07443245205)

![Users need to click "verify email"](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3dpSXiX1FvNuROvbC%2FScreen%20Shot%202019-10-25%20at%201.41.31%20PM.png?alt=media\&token=f721c52f-23da-43ef-adc4-c26cf26d7614)

Once the user clicks on the link in the email, they will be redirected to the [verify](https://docs.airdev.co/canvas/2.0.0-1/using-the-template/reference/pages/verify_email) page. If the email verification token is valid, the user will see the following:

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3eXeI3xkMCFLTWFNq%2FScreen%20Shot%202019-10-25%20at%201.42.39%20PM.png?alt=media\&token=be23920c-baff-4ae8-863b-085c49f2eb41)

If the email verification token is invalid (e.g., the user has already verified his email or the verification link has expired after 24 hours), then the user will see the following:

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3eo1RkqVN-tE6uLWX%2FScreen%20Shot%202019-10-25%20at%201.44.59%20PM.png?alt=media\&token=55cf9206-bb59-4e4b-bfbd-705981369497)

### Additional UI components you can show in the sign up group

* Social media buttons
  * Check the box for *this element is visible on page load* for `Group other buttons (sign up)` and show the social media button group you want to use.
  * Add a workflow action that authenticates with the social media site you'd like to use.
  * Set up the API keys in the relevant plugin (Facebook, LinkedIn, Gmail, Spotify, etc.). If you don't know how to do this, refer to the Plugins section of our Bubble Development Guide.

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3fyMDEldDJfX8iA5-%2FScreen%20Shot%202019-10-25%20at%201.50.53%20PM.png?alt=media\&token=c1ad8294-549e-4889-b953-25bbce6b5237)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3g4YHn-W9qW9b39tl%2FScreen%20Shot%202019-10-25%20at%201.51.21%20PM.png?alt=media\&token=a4ac4c0a-74c4-48d8-8541-d2a9cf9b4fce)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Lu-PHe4bjnpulh4ebwE%2F-Lu-Qs5g42e68ANu5Nft%2FScreenshot%20from%202019-11-18%2016-19-58.png?alt=media\&token=248c2f70-9169-44eb-80a0-b8c97d8ce1b3)

![Choose a Facebook plugin to use.](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Lu-PHe4bjnpulh4ebwE%2F-Lu-QywDMRfGf61oW3Vt%2FScreenshot%20from%202019-11-18%2016-32-49.png?alt=media\&token=e853805d-731c-4b97-9a77-0cfd9bcafee8)

![Press "Enter your API key" to be taken to the view below (in the Plugins tab).](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Lu-PHe4bjnpulh4ebwE%2F-Lu-R100QkeveipX8CFU%2FScreenshot%20from%202019-11-18%2016-33-03.png?alt=media\&token=c64ce364-50e3-4359-81a3-bb2eef47cd89)

![Set up Facebook API - this is found in the Plugins tab of the Bubble editor.](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Lu-PHe4bjnpulh4ebwE%2F-Lu-RCUjTgIkT0gy3J3J%2FScreenshot%20from%202019-11-18%2016-34-51.png?alt=media\&token=e29ceb24-d7bc-49b8-9405-d2d5e1785249)

* User type toggle
  * Check the box for *this element is visible on page load* for `Group User type (sign up)`&#x20;
  * Please remember to change the data source (text) for `Group user type 1` and `Group user type 2`

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3hBQBfCw8TQGR00JE%2FScreen%20Shot%202019-10-25%20at%201.56.16%20PM.png?alt=media\&token=b758d22a-ea79-4314-b166-c4f6dac5c62b)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3gpVvFq9Go70WfrNm%2FScreen%20Shot%202019-10-25%20at%201.53.50%20PM.png?alt=media\&token=2e1213a9-6161-42e0-9a33-1256dc460c30)

* Profile picture and other inputs
  * Check the box for *this element is visible on page load* for `Group profile pic (sign up)` and `unhide Group additional fields (sign up)`&#x20;

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3h7HS1PmJpkPJojPw%2FScreen%20Shot%202019-10-25%20at%201.55.38%20PM.png?alt=media\&token=337a5c1c-8fc9-42ea-9202-94b3820b5113)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-Ls3QQor-a39iHNXy0B4%2F-Ls3hio36sjEa0ymIoFH%2FScreen%20Shot%202019-10-25%20at%201.58.30%20PM.png?alt=media\&token=ae4eb875-9832-433b-9eb0-e13335c48ca3)

To add additional inputs to the sign up flow, simply resize `Group Signup DEADSPACE 2/3/or 4` and add your inputs in the space created.

## Email Templates

App admins can manage all email content centrally from the Admin Portal > Settings Tab > Email Templates Tab.

Some basic templates&#x20;

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a1g4yNp6jGuobZgy1%2FScreen%20Shot%202020-04-10%20at%202.41.36%20PM.png?alt=media\&token=f2b441a7-d452-47ee-af1f-00c1f084b2bd)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a4lEeZ5hUQ29fi4_A%2FScreen%20Shot%202020-04-10%20at%202.55.04%20PM.png?alt=media\&token=a81e1982-5580-4f01-99f3-135de0a66852)

### Creating a new email template

To add a new email template, you will need to create a new entry in the database (Bubble editor > Data tab > App data tab > Email templates > New entry) and complete the following fields:

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a3AtRjE83_RKBUsS4%2FScreen%20Shot%202020-04-10%20at%202.48.12%20PM.png?alt=media\&token=a338e38b-ea45-4a87-b569-ef69a6ac982b)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a3JjhMz3ngQkoOYoa%2FScreen%20Shot%202020-04-10%20at%202.48.44%20PM.png?alt=media\&token=03a8ed3d-ebd5-466d-967e-fb0f19c6c515)

* **Email template name (required)** - Name of the email template
* **Unique name id (required)** - Provide a unique name for the template (without spaces)
* **Description (required)** - Brief description about what this template is used for
* **Subject text (required)** - Subject line of the email
* **Body text (required)** - Body of the email
* **Signature content (optional)** - By default this will be `The [app name] team` but you can add a different text in this field to override it
* **List of mail merge terms (optional)** - This includes a list of mail merge terms (list of texts) that can be used in the email template

Terms that are placed within asterisks (e.g., \**FIRSTNAME\**) are mail merge terms that are dynamic.&#x20;

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a58Ymb7L63mGb0kPC%2FScreen%20Shot%202020-04-10%20at%202.56.44%20PM.png?alt=media\&token=b4c5d54a-ded7-42d3-8c80-2d5c12d743d6)

{% hint style="warning" %}
Email templates will only work if: 1) Your bubble app is not on a hobby plan (you can only schedule API workflows on a paid plan) 2) API workflows have been set up for the template and 3) The email template is enabled&#x20;
{% endhint %}

### Email API workflows

![You can find all email workflows under API workflows > Emails workflow folder](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-LwouU9tpE9vAODVJH-w%2F-LwozZSxr3rGjRGZupIj%2FScreen%20Shot%202019-12-23%20at%203.00.49%20PM.png?alt=media\&token=eff7ec71-4c7a-4d33-9a6d-c00d5fdc5d5d)

Each email template is associated with an API workflow in the Emails workflow folder:

* **send\_email\_template**
  * You should use this template API workflow whenever you need to create an API workflow for a new email template.
* **send\_email\_html\_email**
  * API workflow associated with the *Sample email content email template*
  * It is not currently scheduled to fire an email in the app
* **send\_email\_email\_verification**
  * API workflow associated with the *Email verification email template*
  * This email will only be sent if the App Owner has enabled *Require email verification during sign up* under Settings > General Tab
* **send\_email\_welcome\_email**
  * API workflow associated with the *Welcome email template*
  * App Owners can enable this from the Email templates tab
  * If enabled, the email will be sent to users after they complete the sign up process
* **send\_email\_reset\_pw**
  * API workflow associated with *Reset password email template*
  * By default, this email template is always enabled in the app as users should always be able to reset their passwords
* **send\_email\_add\_admin**

  * API workflow associated with *New admin email template*
  * By default, this email template is always enabled in the app. It is used to notify new admins that they've been added to the app.

  **How are mail merge terms used?**

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-LwouU9tpE9vAODVJH-w%2F-Lwp4yctpp8kU-wszMWY%2FScreen%20Shot%202019-12-23%20at%203.27.21%20PM.png?alt=media\&token=aac8223b-0050-4439-8d47-3ae489b870d9)

Mail merge terms will not correspond to any object in the database. Instead, each email template will have its own list of terms that are managed through the email template's API workflow and its find\&replaces.

{% hint style="warning" %}
Please note that if a mail merge term in the email template copy (e.g., \*FIRSTNAME\*) has been changed (\*FIRST\*), you will also have to update the mailmerge term in the API workflow to \*FIRST\*.
{% endhint %}

Documentation on which mail merge terms to use are on recorded on your canvas template's notes. Each API Workflow has a different set of mail merge terms available. You can also view a list available mail merge terms for each template in the edit email template popup.

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-LybMYTap51RSbYdbKUv%2F-LybMp5vM9IT__fcXAIz%2FScreen%20Shot%202020-01-14%20at%2012.57.16%20PM.png?alt=media\&token=3b131735-82ff-4646-a747-a30aa354190f)

![](https://2550662654-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYJWnUT3lUFQk1K9BCK%2F-M4a1-e9EVMitx5cc6jM%2F-M4a5_Y_DI8OEmYDqqKY%2FScreen%20Shot%202020-04-10%20at%202.55.04%20PM.png?alt=media\&token=4d64efa7-be86-46fb-bb23-502a9c16710a)
