A Concourse resource that sends emails.
Add the following Resource Type to your Concourse pipeline
resource_types:
- name: email
type: docker-image
source:
repository: pcfseceng/email-resource
Look at the demo pipeline for a complete example.
This resource acts as an SMTP client, using PLAIN
auth over TLS. So you need an SMTP server that supports all that.
For development, we've been using Amazon SES with its SMTP support
Within smtp:
host
: Required. SMTP Host nameport
: Required. SMTP Port, must be entered as a stringanonymous
: Optional. Whether or not to require credential. true/false are valid options. If omitted default is falseusername
: Required, Conditionally. Username to authenticate with. Ignored ifanonymous: true
password
: Required, Conditionally. Password to authenticate with. Ignored ifanonymous: true
skip_ssl_validation
: Optional. Whether or not to skip ssl validation. true/false are valid options. If omitted default is falseca_cert
: Optional. Certificates content to verify servers with custom certificates. Only considered ifskip_ssl_validation
isfalse
.host_origin
: Optional. Host to sendHello
from. If not providedlocalhost
is usedlogin_auth
: Optional. This will enable the flag to use Login Auth for authenticated. true/false are valid options. If omitted default is false
Within source:
from
: Required. Email Address to be sent from.to
: Required.Conditionally. Array of email addresses to send email to. Not required if job params contains a file reference that has to recipients.cc
: Optional Array of email addresses to cc send email to.bcc
: Optional Array of email addresses to bcc send email to.
An example source configuration is below.
resources:
- name: send-an-email
type: email
source:
smtp:
host: smtp.example.com
port: "587" # this must be a string
username: a-user
password: my-password
from: build-system@example.com
to: [ "dev-team@example.com", "product@example.net" ] #optional if `params.additional_recipient` is specified
An example source configuration is below supporting sending email when anonymous is permitted.
resources:
- name: send-an-email
type: email
source:
smtp:
host: smtp.example.com
port: "587" # this must be a string
anonymous: true
from: build-system@example.com
to: [ "dev-team@example.com", "product@example.net" ]
An exmaple using custom certificates:
resources:
- name: send-an-email
type: email
source:
smtp:
host: smtp.example.com
port: "587" # this must be a string
anonymous: true
ca_cert: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
from: build-system@example.com
to: [ "dev-team@example.com", "product@example.net" ]
Note that to
is an array, and that port
is a string.
If you're using fly configure
with the --load-vars-from
(-l
) substitutions, every {{ variable }}
automatically gets converted to a string.
But for literals you need to surround it with quotes.
This is an output-only resource, so check
and in
actions are no-ops.
headers
: Optional. Path to plain text file containing additional mail headerssubject
: Optional. Path to plain text file containing the subject. Eithersubject
orsubject_text
required.subject_text
takes precedence.subject_text
: Optional. The subject as text. Eithersubject
orsubject_text
required.subject_text
takes precedence.body
: Optional. Path to file containing the email body. Eitherbody
orbody_text
required.body_text
takes precedence.body_text
: Optional. The email body as text. Eitherbody
orbody_text
required.body_text
takes precedence.send_empty_body
: Optional. If true, send the email even if the body is empty (defaults tofalse
).to
: Optional. Path to plain text file containing recipients which could be determined at build time. You can run a task before, which figures out the email of the person who committed last to a git repository (git -C $source_path --no-pager show $(git -C $source_path rev-parse HEAD) -s --format='%ae' > output/email.txt
). This file can contain,
delimited list of email address if wanting to send to multiples.to_text
: Optional. The,
delimited list of to addresses.to_text
appends to anyto
in params or sourcecc
: Optional. Path to plain text file containing recipients which could be determined at build time. This file can contain,
delimited list of email address if wanting to send to multiples.cc_text
: Optional. The,
delimited list of cc addresses.cc_text
appends to anycc
in params or sourcebcc
: Optional. Path to plain text file containing recipients which could be determined at build time. This file can contain,
delimited list of email address if wanting to send to multiples.bcc_text
: Optional. The,
delimited list of bcc addresses.bcc_text
appends to anybcc
in params or sourcedebug
: Optional. If set to"true"
(as a string) additional information send to stderrattachment_globs:
Optional. If provided will attach any file to the email that matches the glob path(s)
For example, a build plan might contain this:
- put: send-an-email
params:
subject: generated-subject-file
body: generated-body-file
For example, a build plan might contain this if using generated list of recipient(s):
- put: send-an-email
params:
subject: generated-subject-file
body: generated-body-file
to: generated-to-file
You can use the values below in any of the source files or text properties to access the corresponding metadata made available by concourse, as documented here
${BUILD_ID}
${BUILD_NAME}
${BUILD_JOB_NAME}
${BUILD_PIPELINE_NAME}
${ATC_EXTERNAL_URL}
${BUILD_TEAM_NAME}
For example:
- put: send-an-email
params:
subject_text: "Build finished: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}"
body_text: "Build finished: ${ATC_EXTERNAL_URL}/teams/main/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}"
To send HTML email set the headers
parameter to a file containing the following:
MIME-version: 1.0
Content-Type: text/html; charset="UTF-8"
email-resource
is written in Go.
To build the binary yourself, follow these steps:
- Install
Go
. (tested with 1.17) - Clone the repo
git clone git@github.com:pivotal-cf/email-resource.git
cd email-resource
- Build:
go build -o bin/check check/cmd/*.go
go build -o bin/in in/cmd/*.go
go build -o bin/out out/cmd/*.go
To cross compile, set the $GOOS
and $GOARCH
environment variables.
For example: GOOS=linux GOARCH=amd64 go build
.
To run the unit tests, use go test ./... -v
.