---
title: Sending emails with Transactional Email and Serverless using Terraform/OpenTofu
description: Discover how to send emails with Scaleway's Transactional Email and Serverless using Terraform/OpenTofu
tags: transactional-email tem serverless terraform
products:
  - transactional-email
  - terraform
  - functions
  - domains-and-dns
dates:
  validation: 2025-02-11
  posted: 2023-04-27
  validation_frequency: 12
difficulty: beginner
usecase:
  - best-practices
ecosystem:
  - scaleway-only
---
import image from './assets/scaleway-sign-in-super-website.webp'
import image2 from './assets/scaleway-tem-email.webp'

import Requirements from '@macros/iam/requirements.mdx'


In this tutorial, you will learn how to send emails with [Transactional Email](/transactional-email/quickstart/) and [Serverless Functions](/serverless-functions/quickstart/) using a Terraform/OpenTofu configuration file that builds your entire infrastructure, such as a Serverless Function and a website with a registration page hosted on an Object Storage bucket. It also allows you to configure SPF, DKIM, and MX records on your sending domain.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A [domain name](/domains-and-dns/quickstart/)
- [Installed Terraform/OpenTofu](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)

## Clone the GitHub repository

We have created a [GitHub repository](https://github.com/scaleway/tutorial-tem-serverless-terraform) that contains all the code you need to deploy your infrastructure. Open a terminal and clone the repository to your local machine using the following command:

```shell
git clone https://github.com/scaleway/tutorial-tem-serverless-terraform
```

### Files and directories

In the `tutorial-tem-serverless-terraform` directory, you will find three folders: `infra`, `signup-handler`, and `super-product`.

- The `infra` folder holds `main.tf`, the Terraform/OpenTofu configuration file used to deploy your infrastructure.
- The `signup-handler` folder contains the files that will configure your function. The `main.go` file is the entry point for your function.
- The `super-product` folder holds an `index.html.tftpl` file which is a Terraform/OpenTofu template. This file contains an HTML template for the registration page of the website we are creating. This template allows you to automatically create and configure the SPF, MX, and DKIM records needed for your domain, as well as a Serverless Function.

<Message type="tip">
  If you want to use a specific function, you can replace `${DISPATCHER_ENDPOINT}` (line 74) in the `index.html.tftpl` file with your function's endpoint.
</Message>


## Build and deploy your infrastructure

1. Open a terminal and go to the `tutorial-tem-serverless-terraform` directory using the following command:

    ```shell
     cd tutorial-tem-serverless-terraform/infra
    ```

2. Run the following command to download the dependencies and initialize Terraform/OpenTofu:

    ```shell
     terraform init
    ```

3. Run the following command to deploy your infrastructure:

    ```shell
     terraform apply
    ```
4. Type your domain name when prompted to enter a value, and press Enter. You are then asked if you want to perform these actions:

      ```shell
       Plan: 14 to add, 0 to change, 0 to destroy.

       Changes to Outputs:
        + handler_url = (known after apply)
        + url         = (known after apply)

       Do you want to perform these actions?
        Terraform/OpenTofu will perform the actions described above.
        Only 'yes' will be accepted to approve.
      ```

5. Type "yes", then **Enter**. Terraform/OpenTofu will generate your resources. The following output displays once your resources are generated:

    ```shell
     Apply complete! Resources: 14 added, 0 changed, 0 destroyed.

     Outputs:

     handler_url = "https://temdemodct73sjr-tem-demo-signup-handler.functions.fnc.fr-par.scw.cloud"
     url = "https://tem-demo-super-product.s3-website.fr-par.scw.cloud"
    ```

## Sending emails

1. Click the link that displays next to the `url` output. You are redirected to your newly-created website.
2. Enter your username in the **Username** field.
3. Enter your recipient's email address in the **Email address** field. For the purposes of this tutorial, we recommend you enter your own email address.
    <Lightbox image={image} alt="" />

4. Click **Sign in**.
5. Log in to your email address. Your email titled **Welcome to my cool product!** displays in your mailbox.
<Lightbox image={image2} alt="" />