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.
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)
Version: @($) mailsend-go v1.0.10
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
unless '-use' is set.
-use mailprovider - Arranges -smtp, -port and -ssl for you when using
a well known mailprovider. Allowed values:
gmail, yahoo, outlook, gmx, zoho, aol
-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
-log filePath - write log messages to this file
-cs charset - Character set for text/HTML. Default is utf-8
-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)
➤ govulncheck -show verbose ./...
Scanning your code and 138 packages across 2 dependent modules for known vulnerabilities...
Fetching vulnerabilities from the database...
Checking the code against the vulnerabilities...
=== Symbol Results ===
No vulnerabilities found.
=== Package Results ===
No other vulnerabilities found.
=== Module Results ===
Vulnerability #1: GO-2024-3107
Stack exhaustion in Parse in go/build/constraint
More info: https://pkg.go.dev/vuln/GO-2024-3107
Standard library
Found in: stdlib@go1.22.5
Fixed in: stdlib@go1.22.7
Vulnerability #2: GO-2024-3106
Stack exhaustion in Decoder.Decode in encoding/gob
More info: https://pkg.go.dev/vuln/GO-2024-3106
Standard library
Found in: stdlib@go1.22.5
Fixed in: stdlib@go1.22.7
Vulnerability #3: GO-2024-3105
Stack exhaustion in all Parse functions in go/parser
More info: https://pkg.go.dev/vuln/GO-2024-3105
Standard library
Found in: stdlib@go1.22.5
Fixed in: stdlib@go1.22.7
Your code is affected by 0 vulnerabilities.
This scan also found 0 vulnerabilities in packages you import and 3
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.
The current version of mailsend-go is 1.0.10, released on Dec-06-2020
Please look at ChangeLog for what has changed in the current version.
Pre-compiled mailsend-go
binaries are available for the following platforms:
Please download the binaries from the releases page.
Please add an issue if you would need binaries for any other platforms.
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
You will need to install Homebrew first.
First install the custom tap.
$ brew tap
$ brew untap muquit/mailsend-go
$ brew tap muquit/mailsend-go
$ brew install mailsend-go
$ brew uninstall mailsend-go
$ 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
$ 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
$ sudo dpkg -r mailsend-go
$ 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
# rpm -Uvh mailsend-go_linux_64-bit.rpm
# mailsend-go -V
@(#) mailsend-go vx.x.x
# rpm -ev mailsend-go
$ 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
$ 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
You will need to install Scoop first.
c:\> scoop install mailsend-go
c:\> scoop uninstall mailsend-go
After downloading the latest .zip file (e.g., mailsend-go_x.x.x_windows_64-bit.zip), unzip it, and copy mailsend-go-dir\mailsend-go.exe
somewhere in your PATH or run it from the directory.
Compiling from scratch requires the Go programming language toolchain and git. Note: mailsend-go uses go modules for dependency management.
To install the binary:
$ go install github.com/muquit/mailsend-go@latest
The binary will be installed at $GOPATH/bin/ directory.
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:
$ git clone https://github.com/muquit/mailsend-go.git
$ cd mailsend-go
$ make tools
$ make
$ export GO111MODULE=on
$ 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
$ 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:
Building for docker can be done with docker build -t mailsend-go .
. This will also fetch the golang image and create a intermediate image (about 820MB in total). If space is a concern for you, remove them with docker rmi golang:1.13.7
and docker image prune
Running with docker can be done as any other docker image. Everything after the image name will be passed to the program. Example: docker run -it --rm mailsend-go -V
will show the version
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.
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
mailsend-go -info -smtp smtp.gmail.com -port 465 -ssl
Don't worry about the settings of -smtp, -port and -ssl for well known mail providers. This works for gmail, yahoo, outlook, gmx, zoho and aol.
mailsend-go -info -use gmail
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!\nThis is a message"
The embedded new line \n will be converted to a real newline and the final message will show up as two lines.
The environment variable "SMTP_USER_PASS" can be used instead of the flag
-pass
.
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>"
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"
The name of the attachment will be file.pdf. To change the attachmetn name,
use the -name
flag. e.g.
attach -file "/path/file.pdf" -name "report.pdf"
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"
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
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.
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:
# This is a comment.
# The syntax is Name,email address in a line. Name can be empty but comma
# must be specified
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"
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 jdoe@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"
Use the flag -log path_of_log_file.txt
mailsend-go -sub "test log" \
-smtp smtp.example.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jdoe@example.com \
-f "example@gmail.com" \
body -msg "Testing log file" \
-log "/tmp/mailsend-go.log"
The default character set is utf-8
mailsend-go -sub "test character set" \
-smtp smtp.example.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jdoe@example.com \
-from "example@gmail.com" \
-subject "Testing Big5 Charset" \
-cs "Big5" \
body -msg "中文測試"
(Generated from docs/examples.md)
1. How to send mail via smtp.gmail.com?
From May 30, 2022, Google no longer supports the use of third-party apps to sign in to Google Account using username and password. However, an app-specific password can be set for mailsend-go to send mail via smtp.gmail.com. Here are the steps:
If there are any gotchas or need more clarification, please send a pull request or update Issue #49 with your experience and I will update the FAQ.
-- updated: Jul-01-2022
License is MIT
Copyright © 2018-2023 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.
Original mailsend (in C)