Sending emails with Transactional Email and Serverless using Terraform/OpenTofu
In this tutorial, you will learn how to send emails with Transactional Email and Serverless Functions 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.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A domain name
- Installed Terraform/OpenTofu
Clone the GitHub repository
We have created a GitHub repository 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:
git clone https://github.com/scaleway/tutorial-tem-serverless-terraformFiles and directories
In the tutorial-tem-serverless-terraform directory, you will find three folders: infra, signup-handler, and super-product.
- The
infrafolder holdsmain.tf, the Terraform/OpenTofu configuration file used to deploy your infrastructure. - The
signup-handlerfolder contains the files that will configure your function. Themain.gofile is the entry point for your function. - The
super-productfolder holds anindex.html.tftplfile 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.
Build and deploy your infrastructure
-
Open a terminal and go to the
tutorial-tem-serverless-terraformdirectory using the following command:cd tutorial-tem-serverless-terraform/infra -
Run the following command to download the dependencies and initialize Terraform/OpenTofu:
terraform init -
Run the following command to deploy your infrastructure:
terraform apply -
Type your domain name when prompted to enter a value, and press Enter. You are then asked if you want to perform these actions:
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. -
Type "yes", then Enter. Terraform/OpenTofu will generate your resources. The following output displays once your resources are generated:
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
-
Click the link that displays next to the
urloutput. You are redirected to your newly-created website. -
Enter your username in the Username field.
-
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.

-
Click Sign in.
-
Log in to your email address. Your email titled Welcome to my cool product! displays in your mailbox.

Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center