# Sending Emails

Many apps require communication with users via email. For example, sending email confirmation for a scheduled phone call or order confirmation.

### Setting up a Verified Address to Send Email From

A **From** address is required to send emails. Airkit allows for the configuration of different addresses to send emails from. To configure an email, go to [Console](../../console/console). Under the Resources section, select **New**.

There are two options that deal with email. Select **Email Address** and type in a valid email address. Click create. This will allow this email address to be used to send emails. Once create is clicked, Airkit will trigger an authorization email from AWS. Check the email address and click the link to verify the email address. This will enable this email address for sending. Refresh the console page and select the email address. Notice that the **Verification Status** is set to "Success."

#### Example AWS Verification Email with Link to Verify

![2021-04-16\_08-33-26.png](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-a5393d7eb8d860371a6de80deaa72c66ad34ffd1%2Fsending-email-from-airkit-v1715-0.png?alt=media)

### Setting up Your Domain to Ensure Smooth Delivery (DMARC)

It is **ALWAYS** a good idea to setup a domain level verification to ensure smooth delivery so that emails are not caught in anti-spam filtering tools.  In order to do this, a few DNS records will be needed to be added to the domain used in the email address that is in the desired from email address.  Although the act of adding these records typically only takes a few minutes, it is a privileged request in many organizations and may require some lead time (please verify domains early).

To verify a domain, in [Console:](../../console/console)&#x20;

1. Console > Resources > select **New**
2. Under **Capabilities,** select the "Email Domain".
3. Enter the domain in the provided box > Click create
4. Select the new domain from the list. Click the "Open verification instructions" button

#### Example DNS Setup Instructions for Verifying Domain

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-f5dff88e584177dc6c4a0a893f96d199ddba7a39%2Fsending-email-from-airkit-v1715-1.png?alt=media)

In order to set up verification of the domain, a TXT record will be required. To enable DKIM for email verification, additional CNAME records will be required. Once the DNS has been updated, the domain verification will be automatically verified within Airkit, although this process might work within minutes, it could take up to 72 hours depending on DNS settings.

### Adding Verified Email Addresses to an App

Go to your App, go to [Configuration Builder](../../studio/builder-bar/configuration-builder), and scroll down to the _Emails_ section. Select the **New** button.

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-4a2c721614e9b243c60592f30232d79a3e99fa23%2Fsending-email-from-airkit-v1715-2.png?alt=media)

Options will be available based on settings configured in the **Console** above. Adding a singular email address will present a dropdown of configured, available email addresses. Choosing **Email Domain Address** will present a box for an address and a dropdown for qualified domains. Make sure that at least one email is created, as it will be required to send an email.

### Using the Send Email Data Operation

&#x20;Go to [Connection Builder](../../studio/builder-bar/connection-builder) and create a new data flow, label it "Email - Send Thanks." In the **From** dropdown, select the email address. Type a valid email in the **To** field. In order to verify that the send works, this email address will have to be checked. In the _Subject,_ field add the text "Thank you for your interest in our properties." For the text body:

```
"Here at AirHome, we go out of our way to provide you with the best experience   
possible. Thanks for showing interest in our properties. If you have any further  
questions, please don't hesitate to reach out."
```

Hit the play button at the top right of the data operation. The response in the run results should return "true." Checking addressed email should result in a new message with the specified content.

### Testing Sending Email

Once a verified email address & domain have been setup we recommend using an external email testing tool such as [https://www.mail-tester.com](https://www.mail-tester.com) to confirm the ability to send/receive email on behalf of the verified email/domain and also get a report on the DMARC (anti-spam) configurations of the account.  Setting up DMARC properly will ensure more delivered emails.

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-41f811ce680f54ccef0f28c383f77a7d3c285869%2Fsending-email-from-airkit-v1715-3.png?alt=media) &#x20;

### Customizing Email

Beyond sending generic emails, it is possible to customize the addresses, subject, body and even provide an HTML body of an email.

Add an input to the "Email - Send Thanks" Data Flow of type List of Text and name it **emails**. Add a second input of List of Houses (if there is no House Object, do list of Any) and name it **houses**. Set the emails to a list of valid emails of the format:

```javascript
["foo@bar.com", "bar@example.com"]
```

Set the houses to object to an array of houses:

```json
[{  
  "image": {  
    "id": "946c295f-684f-41be-a2ed-2f90df70c35d",  
    "assetKey": "ab69d4c4-5ff9-42b5-b8c7-7e479cc0bbba",  
    "organizationId": "395f62e5-6437-4ef0-9505-8a21a4c89e0b",  
    "visibility": "GLOBAL",  
    "version": 0  
  },  
  "baths": 2,  
  "asking": {  
    "amount": 30000000,  
    "precision": 2,  
    "code": "USD"  
  },  
  "square_feet": 3252,  
  "beds": 3,  
  "date_available": {  
    "year": 2021,  
    "month": 4,  
    "day": 7  
  },  
  "title": "Little Prairie",  
  "contact_email": "bob@example.com"  
},  
{  
  "__id": "4ab32f3a-b0ea-4c6d-b8e9-741dfd559a64",  
  "image": {  
    "id": "a2416138-d560-4ef4-ab40-f2a38549ddbc",  
    "assetKey": "ab69d4c4-5ff9-42b5-b8c7-7e479cc0bbba",  
    "organizationId": "395f62e5-6437-4ef0-9505-8a21a4c89e0b",  
    "visibility": "GLOBAL",  
    "version": 0  
  },  
  "baths": 1.5,  
  "asking": {  
    "amount": 40000000,  
    "precision": 2,  
    "code": "USD"  
  },  
  "square_feet": 2356,  
  "beds": 4,  
  "date_available": {  
    "year": 2021,  
    "month": 11,  
    "day": 8  
  },  
  "title": "Ranch 12",  
  "contact_email": "roger@example.com"  
}]
```

The **To** field on **Send Email** action will work with either a text value of comma-separated email addresses or a list of email address text strings. Put the value **emails** in the _T&#x6F;_&#x66;ield of the Send Email action.

The houses are an AirData App Object. Let's configure our message to contain information about the houses sent in. Create another Data Operation above the email. Select type Transform from the dropdown. Enter the following Airscript into the _Transform Expression:_

```javascript
JOIN(  
  FROM h IN houses SELECT "{{h.title}}, {{FORMAT_CURRENCY(h.asking)}}",  
  "\n"  
)
```

This will take the title and asking price from each house output them in a text string. For more information, check out [Working with Text in Airscript](../../airscript/working-with-text). Update the body text of the _Send Email_ action to:

```
"Here at AirHome, we go out of our way to provide you with the best experience  
possible. Thanks for showing interest in our properties. Our records show you are  
interested in these properties:  
   
{{transform}}  
  
If you have any further questions, please don't hesitate to reach out."
```

Hitting play on this action will now send an email with properties listed.

### HTML Styling

In addition to sending plain text email, it is also possible to send HTML email. It is possible to send  an email with both a plain text and HTML version. Your email client will render the option that is most appropriate for rendering. Set the Body HTML of the send email action to:

```html
"<h1>Thanks!</h1>  
  
<p>Here at <em>AirHome</em>, we go out of our way to provide you with the best experience  
possible. Thanks for showing interest in our properties. Our records show you are  
interested in these properties:</p>  
  
<div style=\"font-size:1.5em;\">  
{{  
SUBSTITUTE(  
transform,  
"\n",  
"<br />"  
)  
}}  
</div>  
  
<p>If you have any further questions, please don't hesitate to reach out.</p>"
```

Sending the email now should return a stylized email.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-28405754f5989c33dc6d2fc9a85151842a0a5124%2Fsending-email-from-airkit-v1715-4.png?alt=media)

This is just one example of how to use email in Airkit. Other examples include sending event registration, sending completed documents, or other confirmation emails.
