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.

Requirements

No requirements.

Providers

NameVersion
nulln/a
templaten/a

Modules

No modules.

Resources

NameType
null_resource.defaultresource
template_file.bodydata source
template_file.subjectdata source

Inputs

NameDescriptionTypeDefaultRequired
bodyEmail body templateanyn/ayes
enabledFlag to enable or disable the sending of emailsstring"true"no
fromFrom address for emailanyn/ayes
hostSMTP Hoststring"smtp.mailgun.org"no
mail_commandCommand to executestring"email"no
passwordPassword to authenticate with the SMTP serverstringn/ayes
portSMTP Portstring"587"no
subjectEmail subject templateanyn/ayes
toEmail recipientslist(string)n/ayes
usernameUsername to authenticate with the SMTP serverstringn/ayes
varsParameters to pass to the body templatemap{}no

Outputs

NameDescription
bodyRendered body of the email
subjectRendered subject of the email