Skip to main content

Module: smtp-mail

Terraform Module to send emails using an SMTP server by calling an external email command.

Introduction

This terraform module uses an external command using the local-exec provisioner to send emails. It's ideally suited for sending transactional emails related to the apply phase. For example, notifying a user of their IAM user account getting created or the deployment of a new ECS application.

NOTE: The null refers to the primary Terraform provider used in this module.

Dependencies

First install the latest release of the email cli tool here: https://github.com/wrouesnel/emailcli/releases

Make sure it exists in your PATH (E.g. /usr/local/bin)

We distribute an Alpine Linux package (emailcli) as part of our toolchain.

curl -sSL https://apk.cloudposse.com/install.sh | sudo bash
apk add emailcli@cloudposse

Usage

module "welcome" {
source = "git::https://github.com/cloudposse/terraform-null-smtp-mail.git?ref=master"
host = "smtp.mailgun.org"
port = "587"
username = "[email protected]"
password = "changeme"
from = "[email protected]"
to = ["[email protected]"]
subject = "Welcome $${first_name}"
body = "Your account has been created. Login here: $${homepage}"

vars = {
first_name = "Example"
homepage = "https://cloudposse.com"
}
}

NOTE: Use the file(...) interpolation function to use a template file.

Variables

Required Variables

body (any) required

Email body template

from (any) required

From address for email

password (string) required

Password to authenticate with the SMTP server

subject (any) required

Email subject template

to (list(string)) required

Email recipients

username (string) required

Username to authenticate with the SMTP server

Optional Variables

host (string) optional

SMTP Host


Default value: "smtp.mailgun.org"

mail_command (string) optional

Command to execute


Default value: "email"

port (string) optional

SMTP Port


Default value: "587"

vars (map) optional

Parameters to pass to the body template


Default value: { }

Context Variables

The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.

enabled (string) optional

Flag to enable or disable the sending of emails
Required: No

Default value: "true"

Outputs

body

Rendered body of the email

subject

Rendered subject of the email

Dependencies

Providers

  • null
  • template

Resources

The following resources are used by this module:

Data Sources

The following data sources are used by this module: