Email

Description

This plugin enables you to send data to an email.

Source Code: https://github.com/go-vela/vela-email

Registry: https://hub.docker.com/r/target/vela-email

Usage

NOTE:

Users should refrain from using latest as the tag for the Docker image.

It is recommended to use a semantically versioned tag instead.

Sample for .vela.yml

secrets:
  - name: username
    engine: native
    key: vela/noreply/username
    type: shared

  - name: password
    engine: native
    key: vela/noreply/password
    type: shared

steps:
  - name: email on success
    image: target/vela-email:latest
    pull: not_present
    secrets: [username, password]
    ruleset:
      status: success
    parameters:
      from: vela-noreply@fakemail.com
      to: [one@email.com, two@email.com]
      sendtype: StartTLS
      auth: LoginAuth
      host: smtp.youremailserver.com
      port: 587
      subject: "{{ .VELA_BUILD_COMMIT }}"
      text: "Author: {{ .VELA_BUILD_AUTHOR }} - Branch: {{ .VELA_BUILD_BRANCH }}"

  - name: email on failure
    image: target/vela-email:latest
    pull: not_present
    secrets: [username, password]
    ruleset:
      status: failure
    parameters:
      from: vela-noreply@fakemail.com
      to: [one@email.com, two@email.com]
      sendtype: StartTLS
      auth: LoginAuth
      host: smtp.youremailserver.com
      port: 587
      subject: "{{ .VELA_BUILD_COMMIT }}"
      text: "Author: {{ .VELA_BUILD_AUTHOR }} - Branch: {{ .VELA_BUILD_BRANCH }}"

Sample for .vela.yml with attachment

secrets:
  - name: username
    engine: native
    key: vela/noreply/username
    type: shared

  - name: password
    engine: native
    key: vela/noreply/password
    type: shared

steps:
  - name: email on success
    image: target/vela-email:latest
    pull: not_present
    secrets: [username, password]
    ruleset:
      status: success
    parameters:
      filename: <filename>
      sendtype: StartTLS
      auth: LoginAuth
      host: smtp.youremailserver.com
      port: 587

  - name: email on failure
    image: target/vela-email:latest
    pull: not_present
    secrets: [username, password]
    ruleset:
      status: failure
    parameters:
      filename: <filename>
      sendtype: StartTLS
      auth: LoginAuth
      host: smtp.youremailserver.com
      port: 587

Sample for email attachment

From: vela-noreply@fakemail.com
To: emailone@email.com, emailtwo@email.com
Subject: Vela Pipeline for {{ .VELA_REPO_FULL_NAME }} {{ .VELA_BUILD_BRANCH }}
Content-Type: text/plain

BuildAuthor:        {{ .VELA_BUILD_AUTHOR }}
BuildAuthorEmail:   {{ .VELA_BUILD_AUTHOR_EMAIL }}
BuildBranch:        {{ .VELA_BUILD_BRANCH }}
BuildCommit:        {{ .VELA_BUILD_COMMIT }}
BuildCreated:       {{ .BuildCreated }}
BuildMessage:       {{ .VELA_BUILD_MESSAGE }}
BuildNumber:        {{ .VELA_BUILD_NUMBER }}
RepositoryFullName: {{ .VELA_REPO_FULL_NAME }}
RepositoryLink:     {{ .VELA_REPO_LINK }}

Secrets

NOTE: Users should refrain from configuring sensitive information in your pipeline in plain text.

Internal

The plugin accepts the following parameters for authentication:

ParameterEnvironment Variable Configuration
usernamePARAMETER_USERNAME, USERNAME
passwordPARAMETER_PASSWORD, PASSWORD

Users can use Vela internal secrets to substitute these sensitive values at runtime:

steps:
  - name: email
    image: target/vela-email:latest
    pull: always
+   secrets: [ username, password ]
    parameters:
-     username: usernameexample@email.com

This example will add the secret to the email step as environment variables:

  • USERNAME=<value>

External

The plugin accepts the following files for authentication:

ParameterVolume Configuration
username/vela/parameters/email/username, /vela/secrets/email/username
password/vela/parameters/email/password, /vela/secrets/email/password

Users can use Vela external secrets to substitute these sensitive values at runtime:

steps:
  - name: email
    image: target/vela-email:latest
    pull: always
    parameters:
-     username: usernameexample@email.com

This example will read the secret value in the volume stored at /vela/secrets/

Parameters

NOTE:

Any values set from a file take precedence over values set from the environment.

VELA environments can be found at VELA Environments

All environment variables are wrapped in sprig template. More information on sprig can be found at sprig docs

The following parameters are used to configure the image:

Logging

ParameterDescriptionRequiredDefaultEnvironment Variables
log_levelset the log level for the plugin (valid options: info, debug, trace)trueinfoPARAMETER_LOG_LEVEL
EMAIL_LOG_LEVEL

Email

ParameterDescriptionRequiredDefaultEnvironment Variables
fromwho the email is being sent fromtrueN/APARAMETER_FROM
EMAIL_FROM
towho the email is being sent totrueN/APARAMETER_TO
EMAIL_TO
cccarbon copy of the email to be sent tofalseN/APARAMETER_CC
EMAIL_CC
bccblind carbon copy of the email to be sent tofalseN/APARAMETER_BCC
EMAIL_BCC
senderwho the email being sent from (will overwrite from)falseN/APARAMETER_SENDER
EMAIL_SENDER
replytoemail address that will be used for repliesfalseN/APARAMETER_REPLYTO
EMAIL_REPLYTO
subjectsubject of the emailfalsedefault subjectPARAMETER_SUBJECT
EMAIL_SUBJECT
textbody of the email in plain text format (HTML will overwrite TEXT)falseN/APARAMETER_TEXT
EMAIL_TEXT
htmlbody of the email in hmtl format (HTML will overwrite TEXT)falsedefault html bodyPARAMETER_HTML
EMAIL_HTML
readreceiptdelivery confirmationfalseN/APARAMETER_READRECEIPT
EMAIL_READRECEIPT

NOTE:

The parameters To, CC, BCC and ReplyTo accepts an array of emails in the format of:

  • [ one@email.com, two@email.com ] or

  • [ firstname lastname <one@email.com>, firstname lastname <two@email.com> ]

Subject, Text body, and HTML body will accept VELA environments with the use of {{ }} such as:

  • {{ .VELA_REPO_FULL_NAME }}

Attachment

ParameterDescriptionRequiredDefaultEnvironment Variables
attachmentfile will be attached to emailfalseN/APARAMETER_ATTACHMENT
EMAIL_ATTACHMENT

Email Filename

ParameterDescriptionRequiredDefaultEnvironment Variables
filenamedata in attached file will be used to populate the email.falseN/APARAMETER_FILENAME
EMAIL_FILENAME

SMTP

ParameterDescriptionRequiredDefaultEnvironment Variables
hostSMTP hosttrueN/APARAMETER_HOST
EMAIL_HOST
portSMTP porttrueN/APARAMETER_PORT
EMAIL_PORT
usernameSMTP usernametrueN/APARAMETER_USERNAME
EMAIL_USERNAME
passwordSMTP passwordtrueN/APARAMETER_PASSWORD
EMAIL_PASSWORD

TLS

ParameterDescriptionRequiredDefaultEnvironment Variables
servernamedefault is set to host address of SMTP serverfalseSMTP hostPARAMETER_SERVERNAME
EMAIL_SERVERNAME
insecureskipverifyverification of the server’s certificate chain and host name. Only use true for testing purposes as this makes TLS susceptible to man-in-middle attacks.falsefalsePARAMETER_SKIPVERIFY
EMAIL_SKIPVERIFY

Encryption

ParameterDescriptionRequiredDefaultEnvironment Variables
sendtypesecurity to send email (valid option: Plain, StartTLS, TLS)trueStartTLSPARAMETER_SENDTYPE
EMAIL_SENDTYPE

Authentication

ParameterDescriptionRequiredDefaultEnvironment Variables
authlogin authentication (valid option: PlainAuth, LoginAuth)trueLoginAuthPARAMETER_AUTH
EMAIL_AUTH

NOTE:

PlainAuth using smtp/auth login for SMTP server.

LoginAuth using a custom login for Office 365/Exchange SMTP server.

Variables

The Plugin provides the following User friendly timestamp variables that can be used in a subject, text, HTML template. These timestamps are converted to Unix timestamps in UTC.

  • BuildCreated
  • BuildEnqueued
  • BuildFinished
  • BuildStarted

Defaults

NOTE: Context-Type options are as follow:

  • text/html for HTML based body of message.
  • text/plain for TEXT based body of message.

Default subject

{{ .VELA_REPO_FULL_NAME }} {{ .VELA_BUILD_BRANCH }} - {{ .VELA_BUILD_COMMIT }}

Default body in HTML

<table>
  <tbody>
    <tr>
      <td width="600">
        <div>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tbody>
              <tr>
                <td>
                  <table width="100%" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td>Build Number:</td>
                        <td>
                          <a href="{{ .VELA_BUILD_LINK }}">
                            {{ .VELA_BUILD_NUMBER }}
                          </a>
                        </td>
                      </tr>
                      <tr>
                        <td>Repo:</td>
                        <td>{{ .VELA_REPO_FULL_NAME }}</td>
                      </tr>
                      <tr>
                        <td>Author:</td>
                        <td>
                          {{ .VELA_BUILD_AUTHOR }} ({{ .VELA_BUILD_AUTHOR_EMAIL
                          }})
                        </td>
                      </tr>
                      <tr>
                        <td>Branch:</td>
                        <td>{{ .VELA_BUILD_BRANCH }}</td>
                      </tr>
                      <tr>
                        <td>Commit:</td>
                        <td>{{ .VELA_BUILD_COMMIT }}</td>
                      </tr>
                      <tr>
                        <td>Started at:</td>
                        <td>{{ .BuildCreated }}</td>
                      </tr>
                    </tbody>
                  </table>
                  <hr />
                  <table width="100%" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td>{{ .VELA_BUILD_MESSAGE }}</td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </td>
    </tr>
  </tbody>
</table>

Template

COMING SOON!

Troubleshooting

You can start troubleshooting this plugin by tuning the level of logs being displayed:

steps:
  - name: send email
    image: target/vela-email:latest
    pull: always
    parameters:
+     log_level: trace
      ...

Below are a list of common problems and how to solve them:

Last modified August 29, 2022: chore: add email plugin (#316) (d1ed4f39)