send-email

A simple utility to send an email (send-email) with attachment(s). For example for use in gitlab pipeline.

TL;DR

  1. create directories:
mkdir conf/
mkdir template/
  1. create template file templates/body.txt
Hello world!
  1. create template file templates/body.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello world!</title>
</head>
<body>
  <b>Hello world!</b>
</body>
</html>
  1. create configuration file conf/mail.yml
smtp:
  hostname: smtp-relay.example.com
  helo_domain: example.com
  port: 2525
mail:
  subject: Hello world!
  from:
    address: [email protected]
    name: Noreply
  to:
  - address: [email protected]
    name: User Name
  templates:
    body:
      text: templates/hello-body.txt
      html: templates/hello-body.html
  1. send email!
$ ./bin/send-email --config conf/hello-world.yml

2022/06/22 17:19:27 [e_mail.client/43983] Info [EMail_Client] Start TCP session to smtp-relay.example.com:2525
2022/06/22 17:19:27 [e_mail.client/43983] Info [EMail_Client] Successfully sent a message from <[email protected]> to 1 recipient(s)
2022/06/22 17:19:27 [e_mail.client/43983] Info [EMail_Client] Close session to smtp-relay.example.com:2525
  1. or send email with attachment!
./bin/send-email --config conf/hello-world.yml -a README.md
  1. or add more attachments!
./bin/send-email --config conf/hello-world.yml -a README.md -a LICENSE

Installation

shards build --production
cp ./bin/send-email /usr/local/bin/

Usage

$ ./bin/send-email --help
Usage: send-email [arguments]
    -c CONFIG, --config=CONFIG       Specifies the name of the configuration file
    -a ATTACHMENT, --attachment=ATTACHMENT
                                     Attachment file to email (can be set multiple times)
    -h, --help                       Show this help

Development

$ sentry -b "crystal build ./src/send-email.cr -o ./bin/send-email" \
       -r "./bin/send-email" \
       --run-args "-c conf/dev.yml"
$ cat conf/dev.yml

smtp:
  hostname: localhost
  helo_domain: localhost
  port: 2525
mail:
  subject: Hello world!
  from:
    address: [email protected]
    name: Noreply
  to:
  - address: [email protected]
    name: User Name

Contributing

  1. Fork it (https://github.com/your-github-user/send-email/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors