Skip to content
mailsend-go is a multi-platform command line tool to send mail via SMTP protocol
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Formula
docs Resolve #6 Mar 12, 2019
files Resolve #6 Mar 12, 2019
scripts
test Resolve #6 Mar 12, 2019
.gitignore first commit Jan 26, 2019
.goreleaser.yml update .goreleaser.yaml for ARM Mar 13, 2019
ChangeLog.md Document was not generated Feb 21, 2019
LICENSE.txt
Makefile update .goreleaser.yaml for ARM Mar 13, 2019
README.md
examples.go Resolve #6 Mar 12, 2019
go.mod
go.sum first commit Jan 26, 2019
main.go
smtp_info.go first commit Jan 26, 2019

README.md

Page Contents

Introduction

mailsend-go is a command line tool to send mail via SMTP protocol. This is the golang incarnation of my C version of mailsend. However, this version is much simpler and all the heavy lifting is done by the package gomail.v2

If you use mailsend, please consider using mailsend-go as no new features will be added to mailsend.

If you have any question, request or suggestion, please enter it in the Issues with appropriate label.

Features

  • Add a mail body
  • Support Multiple Attachments
  • Supports ESMTP Authentication
  • Supports StartTLS and SSL
  • Send mail to a list of users
  • Show SMTP server info
  • Fixes issues of mailsend

Contributing

Please send a pull request if you add features, fix bugs or update the documentation.

If you want to update the documentation, please do not update README.md directly, rather update the Markdown files in docs/ directory. README.md is generated by markdown_helper ruby gem by assembling the individual Markdown files in the docs/ directory. If you would like to generate README.md, type make gen (you will need required tools of course)

Supported Platforms

mailsend-go is written in go, therefore, it can be cross compiled for many platforms from one platform. This is the motivation for me to write it in go.

The compiled binaries for the following platforms are supplied:

  • Linux (tgz, debian and rpm)
  • Windows (zip)
  • MacOS (tgz, Homebrew)

Please add an issue if you would need binaries for any other platforms.

Synopsis

 Version: @($) mailsend-go v1.0.4

 mailsend-go [options]
  Where the options are:
  -debug                 - Print debug messages
  -sub subject           - Subject
  -t to,to..*            - email address/es of the recipient/s. Required
  -list file             - file with list of email addresses. 
                           Syntax is: Name, email_address
  -fname name            - name of sender
  -f address*            - email address of the sender. Required
  -cc cc,cc..            - carbon copy addresses
  -bcc bcc,bcc..         - blind carbon copy addresses
  -rt rt                 - reply to address
  -smtp host/IP*         - hostname/IP address of the SMTP server. Required
  -port port             - port of SMTP server. Default is 587
  -domain domain         - domain name for SMTP HELO. Default is localhost
  -info                  - Print info about SMTP server
  -ssl                   - SMTP over SSL. Default is StartTLS
  -verifyCert            - Verify Certificate in connection. Default is No
  -ex                    - show examples
  -help                  - show this help
  -q                     - quiet
  -V                     - show version and exit
  auth                   - Auth Command
    -user username*      - username for ESMTP authentication. Required
    -pass password*      - password for EMSPTP authentication. Required
  body                   - body command for attachment for mail body
    -msg msg             - message to show as body 
    -file path           - or path of a text/HTML file
    -mime-type type      - MIME type of the body content. Default is detected
  attach                 - attach command. Repeat for multiple attachments
    -file path*          - path of the attachment. Required
    -name name           - name of the attachment. Default is filename
    -mime-type type      - MIME-Type of the attachment. Default is detected
    -inline              - Set Content-Disposition to "inline". 
                           Default is "attachment"
  header                 - Header Command. Repeat for multiple headers
    -name header         - Header name
    -value value         - Header value

The options with * are required. 

Environment variables:
   SMTP_USER_PASS for auth password (-pass)
    

Version

The current version of mailsend-go is v1.0.3, released on Feb-20-2019.

Please look at ChangeLog for what has changed in the current version.

Downloading and Installing

Pre-compiled mailsend-go binaries for Windows, Linux and MacOS can be downloaded from the releases page.

Files Platform
mailsend-go_x.x.x_checksums.txt SHA256 checksum files for the binaries
mailsend-go_x.x.x_windows_32-bit.zip Windows 32 bit
mailsend-go_x.x.x_windows_64-bit.zip Windows 64 bit
mailsend-go_x.x.x_linux_64-bit.tar.gz Linux 64 bit
mailsend-go_x.x.x_mac_64-bit.tar.gz Mac OS X 64 bit
mailsend-go_linux_64-bit.rpm RPM for Linux 64 bit
mailsend-go_linux_64-bit.deb Debian package for Linux 64 bit

Before installing, please make sure to verify the checksum.

When the tgz or zip archives are extracted they create a directory mailsend-go-dir/ with the content.

Example

    $ tar -tvf mailsend-go_x.x.x_linux_64-bit.tar.gz
	-rw-r--r--  0 muquit staff    1081 Jan 26 15:21 mailsend-go-dir/LICENSE.txt
	-rw-r--r--  0 muquit staff   14242 Jan 27 13:47 mailsend-go-dir/README.md
	-rw-r--r--  0 muquit staff   16866 Jan 27 13:47 mailsend-go-dir/docs/mailsend-go.1
	-rwxr-xr-x  0 muquit staff 5052992 Feb  9 19:23 mailsend-go-dir/mailsend-go
	$ unzip -l mailsend-go_x.x.x_windows_64-bit.zip
	Archive:  mailsend-go_x.x.x_windows_64-bit.zip
	  Length      Date    Time    Name
	---------  ---------- -----   ----
		 1081  01-26-2019 15:21   mailsend-go-dir/LICENSE.txt
		14242  01-27-2019 13:47   mailsend-go-dir/README.md
		16866  01-27-2019 13:47   mailsend-go-dir/docs/mailsend-go.1
	  4933632  02-09-2019 19:23   mailsend-go-dir/mailsend-go.exe
	---------                     -------
	  4965821                     4 files

Installing using Homebrew on Mac

You will need to install Homebrew first.

Install

First install the custom tap.

    $ brew tap muquit/mailsend-go https://github.com/muquit/mailsend-go.git
    $ brew install mailsend-go

Uninstall

    $ brew uninstall mailsend-go

Installing the debian package on Ubuntu/Debian

Inspect the package content

    $ dpkg -c mailsend-go_linux_64-bit.deb
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/share/
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/share/docs/
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/share/docs/mailsend-go/
	-rw-r--r-- 0/0            1081 2019-02-10 20:17 usr/local/share/docs/mailsend-go/LICENSE.txt
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/bin/
	-rwxr-xr-x 0/0         5052992 2019-02-10 20:17 usr/local/bin/mailsend-go
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/share/man/
	drwxr-xr-x 0/0               0 2019-02-10 20:17 usr/local/share/man/man1/
	-rw-r--r-- 0/0           20896 2019-02-10 20:17 usr/local/share/man/man1/mailsend-go.1
	-rw-r--r-- 0/0           19236 2019-02-10 20:17 usr/local/share/docs/mailsend-go/README.md

Install

    $ sudo dpkg -i mailsend-go_linux_64-bit.deb 
	Selecting previously unselected package mailsend-go.
	(Reading database ... 4039 files and directories currently installed.)
	Preparing to unpack mailsend-go_linux_64-bit.deb ...
	Unpacking mailsend-go (x.x.x) ...
	Setting up mailsend-go (x.x.x) ...
    $ mailsend-go -V
    @(#) mailsend-go vx.x.x

Uninstall

    $ sudo dpkg -r mailsend-go

Install the RPM package

Inspect the package content

    $ rpm -qlp mailsend-go_linux_64-bit.rpm
    /usr/local/bin/mailsend-go
    /usr/local/share/docs/mailsend-go/LICENSE.txt
    /usr/local/share/docs/mailsend-go/README.md
    /usr/local/share/man/man1/mailsend-go.1

Install/Upgrade

    # rpm -Uvh mailsend-go_linux_64-bit.rpm
    # mailsend-go -V
    @(#) mailsend-go vx.x.x

Uninstall

    # rpm -ev mailsend-go

Install from archive

Inspect the content

    $ tar -tvf mailsend-go_x.x.x_linux_64-bit.tar.gz
    -rw-r--r--  0 muquit staff    1081 Jan 26 15:21 mailsend-go-dir/LICENSE.txt
    -rw-r--r--  0 muquit staff   14242 Jan 27 13:47 mailsend-go-dir/README.md
    -rw-r--r--  0 muquit staff   16866 Jan 27 13:47 mailsend-go-dir/docs/mailsend-go.1
    -rwxr-xr-x  0 muquit staff 5052992 Feb  9 19:23 mailsend-go-dir/mailsend-go
    $ unzip -l mailsend-go_x.x.x_windows_64-bit.zip
    Archive:  mailsend-go_x.x.x_windows_64-bit.zip
      Length      Date    Time    Name
    ---------  ---------- -----   ----
     1081  01-26-2019 15:21   mailsend-go-dir/LICENSE.txt
    14242  01-27-2019 13:47   mailsend-go-dir/README.md
    16866  01-27-2019 13:47   mailsend-go-dir/docs/mailsend-go.1
      4933632  02-09-2019 19:23   mailsend-go-dir/mailsend-go.exe
    ---------                     -------
      4965821                     4 files

Install Linux

    $ tar -xf mailsend-go_x.x.x_linux_64-bit.tar.gz
    $ sudo cp mailsend-go-dir/mailsend-go /usr/local/bin
    $ sudo cp mailsend-go-dir/doc/mailsend-go.1 /usr/local/share/man/man1

Install Windows

Unzip mailsend-go_x.x.x_windows_64-bit.zip and copy mailsend-go-dir\mailsend-go.exe somewhere in your PATH or run it from the directory.

Compiling

Compiling from scratch requires the Go programming language toolchain and git. Note: mailsend-go uses go modules for dependency management.

To download, build and install (or upgrade) mailsend-go, run:

    $ go get -u github.com/muquit/mailsend-go

If you see the error message go: cannot find main module; see 'go help modules', make sure GO111MODULE environment variable is not set to on. Unset it by typing unset GO111MODULE

To compile yourself:

  • If you are using very old version of go, install dependencies by typing:
    $ make tools
    $ make
  • If you are using go 1.11+, dependencies will be installed via go modules. If you cloned mailsend-go inside your $GOPATH, you have to set env var:
    $ export GO111MODULE=on
  • Finally compile mailsend-go by typing:
    $ make

As mailsend-go uses go modules, it can be built outside $GOPATH e.g.

    $ cd /tmp
    $ git clone https://github.com/muquit/mailsend-go.git
    $ cd mailsend-go
    $ make
    $ ./mailsend-go -V
    @(#) mailsend-go v1.0.1
  • List the packages used (if you are outside $GOPATH)
    $ go list -m "all"
    github.com/muquit/mailsend-go
    gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc
    gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df

Type make help for more targets:

Examples

Each example mailsend-go command is a single line. In Unix back slash \ can be used to continue in the next line. Also in Unix, use single quotes instead of double quotes, otherwise if input has any shell character like $ etc, it will get expanded by the shell.

Show SMTP server information

StartTLS will be used if server supports it

  mailsend-go -info -smtp smtp.gmail.com -port 587
[S] 220 smtp.gmail.com ESMTP k185-v6sm17739711qkd.27 - gsmtp
[C] HELO localhost
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-STARTTLS
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] STARTTLS
[S] 220-2.0.0 Ready to start TLS
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
Certificate of smtp.gmail.com:
 Version: 3 (0x3)
 Serial Number: 149685795415515161014990164765 (0x1e3a9301cfc7206383f9a531d)
 Signature Algorithm: SHA256-RSA
 Subject: CN=Google Internet Authority G3,O=Google Trust Services,C=US
 Issuer: GlobalSign
 Not before: 2017-06-15 00:00:42 +0000 UTC
 Not after: 2021-12-15 00:00:42 +0000 UTC
[C] QUIT
[S] 221-2.0.0 closing connection k185-v6sm17739711qkd.27 - gsmtp

Use SSL. Note the port is different

  mailsend-go -info -smtp smtp.gmail.com -port 465 -ssl

Send mail with a text message

Notice "auth" is a command and it takes -user and -pass arguments. "body" is also a command and here it took -msg as an argument. The command "body" can not repeat, if specified more than once, the last one will be used.

    mailsend-go -sub "Test"  -smtp smtp.gmail.com -port 587 \
     auth \
      -user jsnow@gmail.com -pass "secret" \
     -from "jsnow@gmail.com" -to  "mjane@example.com" \
     body \
       -msg "hello, world!"

The environment variable "SMTP_USER_PASS" can be used instead of the flag -pass.

Send mail with a HTML message

    mailsend-go -sub "Test"  \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user jsnow@gmail.com -pass "secret" \
    -from "jsnow@gmail.com"  \
    -to  "mjane@example.com" -from "jsnow@gmail.com" \
    body \
     -msg "<b>hello, world!</b>"

Attach a PDF file

MIME type will be detected. Content-Disposition will be set to "attachment", Content-Transfer-Encoding will be "Base64". Notice, "attach" is a command it took -file as an arg. The command "attach" can repeat.

    mailsend-go -sub "Test"  \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user jsnow@gmail.com -pass "secret" \
    -from "jsnow@gmail.com"  \
    -to  "mjane@example.com" -from "jsnow@gmail.com" \
    body \
     -msg "A PDF file is attached" \
    attach \
     -file "/path/file.pdf"

Attach a PDF file and an image

Notice, the "attach" command is repeated here.

    mailsend-go -sub "Test"  \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user jsnow@gmail.com -pass "secret" \
    -from "jsnow@gmail.com"  \
    -to  "mjane@example.com" -from "jsnow@gmail.com" \
    body \
     -msg "A PDF file and a PNG file is attached" \
    attach \
     -file "/path/file.pdf" \
    attach \
     -file "/path/file.png"

Attach a PDF file and embed an image

Content-Disposition for the image will be set to "inline". It's an hint to the mail reader to display the image on the page. Note: it is just a hint, it is up to the mail reader to respect it or ignore it.

    mailsend-go -sub "Test"  \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user jsnow@gmail.com -pass "secret" \
    -from "jsnow@gmail.com"  \
    -to  "mjane@example.com" -from "jsnow@gmail.com" \
    body \
     -msg "A PDF file is attached, image should be displayed inline" \
    attach \
     -file "/path/file.pdf" \
    attach \
     -file "/path/file.png" \
     -inline

Set Carbon Copy and Blind Carbon copy

    mailsend-go -sub "Testing -cc and -bcc" \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user example@gmail.com -pass "secret" \
     -to jsoe@example.com \
     -f "example@gmail.com" \
     -cc "user1@example.com,user2@example.com" \
     -bcc "foo@example.com" \
     body -msg "Testing Carbon Copy and Blind Carbon copy"

Cc addresses will be visible to the recipients but Bcc address will not be.

Send mail to a list of users

Create a file with list of users. The syntax is Name,email_address in a line. Name can be empty but comma must be specified. Example of a list file:

John Snow,jsnow@example.com
Mary Jane,mjane@example.com
,foobar@example.com

Specify the list file with -list flag.

    mailsend-go -sub "Test sending mail to a list of users" \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user example@gmail.com -pass "secret" \
        -f "me@example.com" \
        -to "xyz@example.com" \
        body \
        -msg "This is a test of sendmail mail to a list of users" \
        attach \
            -file "cat.jpg" \
         attach \
            -file "flower.jpg" \
            -inline \
         -list "list.txt"

Add Custom Headers

Use the command "header" to add custom headers. The command "header" can be repeated.

    mailsend-go -sub "Testing custom headers" \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user example@gmail.com -pass "secret" \
     -to jsoe@example.com \
     -f "example@gmail.com" \
     body -msg "Testing adding Custom headers"
     header \
         -name "X-MyHeader-1" -value "Value of X-MyHeader-1" \
     header \
         -name "X-MyHeader-2" -value "Value of X-MyHeader-2"


(Generated from docs/examples.md)


License (is MIT)

License is MIT

Copyright © 2018-2019 muquit@muquit.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See Also

Original mailsend (in C)


You can’t perform that action at this time.