Skip to content

muquit/mailsend-go

Repository files navigation

Downloads

Table Of 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 However, this package is not maintained anymore. Therefore, I forked it to gomail (starting from mailsend-go v1.0.11-b1 Aug-24-2025). The main purpose of this fork is to add XOAUTH2 support (Bug #68)

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.

NOTE: XOAUTH2 support was added in v1.0.11-b1 (Released on Aug-24-2025)

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

XOAUTH2 support

XOAUTH2 support is available in v1.0.11-b1 (Released on Aug-24-2025). mailsend-go itself does not implement full OAuth2 flow because implementing full OAuth2 would require managing web browser redirects, secure token storage across different platforms and maintaing state of token refresh cycles.

Therefore, I've created a companion tool called oauth-helper for token management. This separation keeps mailsend-go simple and secure while giving you full control over how tokens are obtained and stored. For automation, just pipe token from oauth-helper directly into mailsend-go.

Please visit oauth-helper page for details. It has examples on how to integrate with mailsend-go and XOAUTH2.

Please create an Issues if you need help or have any questions.

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

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-toc-go 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)

Synopsis

 Version: @($) mailsend-go v1.0.11
 https://github.com/muquit/mailsend-go
 Compiled with go version: go1.25.1

 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 and exit
  -printCerts            - Print Certificates in connection with -info. Default is No
  -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*       - For basic auth: username for ESMTP authentication
                           For OAuth2: email address of the authenticated account
                           Required for both auth methods
   -pass password*       - password for ESMTP authentication. Required for basic auth
   -oauth2               - Use OAuth2 XOAUTH2 authentication instead of basic auth
   -token access_token*  - OAuth2 access token. Required when -oauth2 is used
  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)
   SMTP_OAUTH_TOKEN for OAuth2 access token (-token)

XOAUTH2 helper:
   Please visit the following link for a tool to help obtain
   OAuth2 access token for mailsend-go:
     https://github.com/muquit/oauth-helper

Vulnerability Check

➤ govulncheck --version
Go: go1.25.1
Scanner: govulncheck@v1.1.4
DB: https://vuln.go.dev
DB updated: 2025-09-24 19:21:41 +0000 UTC

No vulnerabilities found.
➤ govulncheck -show verbose ./...
Fetching vulnerabilities from the database...

Checking the code against the vulnerabilities...

The package pattern matched the following 2 root packages:
  github.com/muquit/mailsend-go/pkg/version
  github.com/muquit/mailsend-go
Govulncheck scanned the following 2 modules and the go1.25.1 standard library:
  github.com/muquit/mailsend-go
  github.com/muquit/gomail@v0.0.0-20250704205629-a34fa7a15a08

No vulnerabilities found.

Version 1.0.11 (Apr-04-2026)

The current stable ersion of mailsend-go is 1.0.11, released on Apr-04-2026.

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

Downloading and Installing

Pre-compiled mailsend-go binaries are available for the following platforms:

  • Windows - 32 and 64 bit
  • Linux - 64 bit (tgz)
  • MacOS - 64 bit (tgz, Homebrew)
  • Raspberry pi - 32 bit (tgz)

Please download the binaries from the releases page.

Please add an Issues 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 bin/mailsend-go-v1.0.11-linux-amd64.d.tar.gz
-rw-r--r--  0 muquit staff    1084 Jan 16 20:10 mailsend-go-v1.0.11-linux-amd64.d/LICENSE.txt
-rw-r--r--  0 muquit staff   33880 Jan 16 20:10 mailsend-go-v1.0.11-linux-amd64.d/README.md
-rwxr-xr-x  0 muquit staff 5427384 Jan 16 20:10 mailsend-go-v1.0.11-linux-amd64.d/mailsend-go-v1.0.11-linux-amd64
-rw-r--r--  0 muquit staff   34185 Jan 16 20:10 mailsend-go-v1.0.11-linux-amd64.d/mailsend-go.1
-rw-r--r--  0 muquit staff     903 Jan 16 20:10 mailsend-go-v1.0.11-linux-amd64.d/platforms.txt
➤ unzip -l bin/mailsend-go-v1.0.11-windows-amd64.d.zip
Archive:  bin/mailsend-go-v1.0.11-windows-amd64.d.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     1084  01-16-2026 20:10   mailsend-go-v1.0.11-windows-amd64.d/LICENSE.txt
    33880  01-16-2026 20:10   mailsend-go-v1.0.11-windows-amd64.d/README.md
  5563904  01-16-2026 20:10   mailsend-go-v1.0.11-windows-amd64.d/mailsend-go-v1.0.11-windows-amd64.exe
    34185  01-16-2026 20:10   mailsend-go-v1.0.11-windows-amd64.d/mailsend-go.1
      903  01-16-2026 20:10   mailsend-go-v1.0.11-windows-amd64.d/platforms.txt
---------                     -------
  5633956                     5 files

After extracting the archive, copy the binary somewhere in your PATH. Example:

sudo /bin/cp -fv \
         mailsend-go-v1.0.11-linux-amd64.d/mailsend-go-v1.0.11-linux-amd64 \
         /usr/local/bin/mailsend-go
sudo /bin/cp -fv \
         mailsend-go-v1.0.11-linux-amd64.d/mailsend-go.1 \
         /usr/share/main/man1

Installing using Homebrew on Mac

You will need to install Homebrew first. Note: Homebrew formula will be availbale only for released version of mailsend-go

Installing

First install the custom tap.

brew tap muquit/formulae
brew install mailsend-go

Or use auto-tap (installs in one command):

brew install muquit/formulae/mailsend-go

Note: If you previously used the old dedicated tap (muquit/mailsend-go), you may get an ambiguity error. Migrate to the new tap with:

 brew uninstall mailsend-go
 brew untap muquit/mailsend-go
 brew install muquit/formulae/mailsend-go

Updating

brew upgrade mailsend-go

Uninstalling

brew uninstall mailsend-go

To remove the tap:

brew untap muquit/formulae

Compiling from source

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
    $ ./mailsend-go -V
  • List the packages used (if you are outside $GOPATH)
    $ go list -m "all"
    github.com/muquit/mailsend-go
    github.com/muquit/gomail v0.0.0-20250327010414-6846ede5e07d
    github.com/muquit/quotedprintable v0.0.0-20250204043250-71206103869d

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. The directory test/ has some test scripts.

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

Print SMTP server certificate chain

  mailsend-go -info -smtp smtp.gmail.com -port 587 -printCerts
[S] 220 smtp.gmail.com ESMTP 6a1803df08f44-80166e2f32bsm34741116d6.41 - 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
[C] QUIT
[S] 221-2.0.0 closing connection 6a1803df08f44-80166e2f32bsm34741116d6.41 - gsmtp

=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1301
Server Name: smtp.gmail.com
Negotiated Protocol:

Certificate Chain (3 certificates):

--- Certificate 1 ---
Subject: CN=smtp.gmail.com
Issuer: CN=WR2,O=Google Trust Services,C=US
Serial Number: 14461562026188826353951632455228095006
Not Before: 2025-09-08T08:36:45Z
Not After: 2025-12-01T08:36:44Z
Is CA: false
DNS Names: smtp.gmail.com
Key Usage: Digital Signature
Status: Valid

--- Certificate 2 ---
Subject: CN=WR2,O=Google Trust Services,C=US
Issuer: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Serial Number: 170058220837755766831192027518741805976
Not Before: 2023-12-13T09:00:00Z
Not After: 2029-02-20T14:00:00Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid

--- Certificate 3 ---
Subject: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Issuer: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE
Serial Number: 159159747900478145820483398898491642637
Not Before: 2020-06-19T00:00:42Z
Not After: 2028-01-28T00:00:42Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid

--- Certificate Fingerprints (Leaf) ---
SHA-1: 28:88:45:90:10:20:88:BA:87:2E:0E:7C:3A:12:D6:35:EC:26:AE:90
SHA-256: 6F:F8:E2:F5:D4:AE:5A:FF:92:4A:5F:AC:88:80:14:3A:30:33:7A:CF:EE:33:94:82:EF:2A:93:47:80:E4:18:EF
=====================================
   mailsend-go -info -smtp smtp.gmail.com -port 465 -ssl -printCerts
[S] 220 smtp.gmail.com ESMTP 6a1803df08f44-80166781d27sm35134546d6.45 - 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-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] QUIT
[S] 221-2.0.0 closing connection 6a1803df08f44-80166781d27sm35134546d6.45 - gsmtp

=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1301
Server Name: smtp.gmail.com
Negotiated Protocol:

Certificate Chain (3 certificates):

--- Certificate 1 ---
Subject: CN=smtp.gmail.com
Issuer: CN=WR2,O=Google Trust Services,C=US
Serial Number: 14461562026188826353951632455228095006
Not Before: 2025-09-08T08:36:45Z
Not After: 2025-12-01T08:36:44Z
Is CA: false
DNS Names: smtp.gmail.com
Key Usage: Digital Signature
Status: Valid

--- Certificate 2 ---
Subject: CN=WR2,O=Google Trust Services,C=US
Issuer: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Serial Number: 170058220837755766831192027518741805976
Not Before: 2023-12-13T09:00:00Z
Not After: 2029-02-20T14:00:00Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid

--- Certificate 3 ---
Subject: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Issuer: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE
Serial Number: 159159747900478145820483398898491642637
Not Before: 2020-06-19T00:00:42Z
Not After: 2028-01-28T00:00:42Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid

--- Certificate Fingerprints (Leaf) ---
SHA-256: 6F:F8:E2:F5:D4:AE:5A:FF:92:4A:5F:AC:88:80:14:3A:30:33:7A:CF:EE:33:94:82:EF:2A:93:47:80:E4:18:EF
SHA-1: 28:88:45:90:10:20:88:BA:87:2E:0E:7C:3A:12:D6:35:EC:26:AE:90
=====================================
    mailsend-go -info -smtp smtp-mail.outlook.com -port 587 -printCerts
[S] 220 MN2PR01CA0065.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 27 Sep 2025 00:29:10 +0000 [08DDFAA3FED0C1E0]
[C] HELO localhost
[C] EHLO localhost
[S] 250-MN2PR01CA0065.outlook.office365.com Hello [x.x.x.x]
[S] 250-SIZE 157286400
[S] 250-PIPELINING
[S] 250-DSN
[S] 250-ENHANCEDSTATUSCODES
[S] 250-STARTTLS
[S] 250-8BITMIME
[S] 250-BINARYMIME
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] STARTTLS
[S] 220-2.0.0 SMTP server ready
[C] EHLO localhost
[S] 250-MN2PR01CA0065.outlook.office365.com Hello [x.x.x.x]
[S] 250-SIZE 157286400
[S] 250-PIPELINING
[S] 250-DSN
[S] 250-ENHANCEDSTATUSCODES
[S] 250-AUTH LOGIN XOAUTH2
[S] 250-8BITMIME
[S] 250-BINARYMIME
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] QUIT
[S] 221-2.0.0 Service closing transmission channel

=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1302
Server Name: smtp-mail.outlook.com
Negotiated Protocol:

Certificate Chain (2 certificates):

--- Certificate 1 ---
Subject: CN=outlook.com,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US
Issuer: CN=DigiCert Cloud Services CA-1,O=DigiCert Inc,C=US
Serial Number: 10535063011692331098818316272276424549
Not Before: 2025-03-29T00:00:00Z
Not After: 2026-03-28T23:59:59Z
Is CA: false
DNS Names: *.clo.footprintdns.com, *.hotmail.com, *.internal.outlook.com, *.live.com, *.nrb.footprintdns.com, *.office.com, *.office365.com, *.outlook.com, *.outlook.office365.com, attachment.outlook.live.net, attachment.outlook.office.net, attachment.outlook.officeppe.net, attachments.office.net, attachments-sdf.office.net, ccs.login.microsoftonline.com, ccs-sdf.login.microsoftonline.com, hotmail.com, mail.services.live.com, office365.com, outlook.com, outlook.office.com, substrate.office.com, substrate-sdf.office.com
Key Usage: Digital Signature, Key Encipherment
Status: Valid

--- Certificate 2 ---
Subject: CN=DigiCert Cloud Services CA-1,O=DigiCert Inc,C=US
Issuer: CN=DigiCert Global Root CA,OU=www.digicert.com,O=DigiCert Inc,C=US
Serial Number: 20058375873168194746987232153701302504
Not Before: 2020-09-25T00:00:00Z
Not After: 2030-09-24T23:59:59Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid

--- Certificate Fingerprints (Leaf) ---
SHA-1: A6:F7:EC:FB:2B:F6:31:B3:A8:4F:EB:B0:9F:FD:BB:4E:3B:0F:42:11
SHA-256: 4F:94:1A:8E:50:52:5E:09:24:4F:8F:FE:75:65:E1:6A:51:DD:10:47:04:74:94:6A:0F:BA:84:6A:86:E4:DE:8C
=====================================

Use default settings for well known mail providers

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

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!\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.

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>"

The environment variable "SMTP_OAUTH_TOKEN" can be used instead of the flag -token.

Send mail with a HTML message, use XOAUTH2

    export SMTP_OAUTH_TOKEN='your_access_token'
    mailsend-go -sub "Test"  \
    -smtp smtp.gmail.com -port 587 \
    auth \
     -user jsnow@gmail.com \
     -oauth2 \
    -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"

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"

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:

    # 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"

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 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"

Write logs to a file

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"

Specify a different character set

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)


Frequently Asked Questions (FAQ)

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:

  • Login to your gmail account
  • Click on the Profile icon at the right side and then click on Manage your Google Account
  • Click on Security link from the list on the left sidebar.
  • Now you have to enable 2FA (Two Factor Authentication). Think carefully if you are going to do that for your main account. I used a test account and it does not seem to ask for 2FA code while sending email using smtp.gmail.com. However, it will require to enter 2FA code when you login to gmail.com. By default it sends 2FA code to your phone#, which is not secure. Configure to use Google Authenticator App instead for 2FA.
  • After 2FA is enabled, Click on Security link again. Select 2-Step Verification. Generate the app specific password by clicking on the App Passwords link. Specify mailsend-go as the app (I don't think it matters).
  • Use the username and this app specific password to send mail via smtp.gmail.com. It does not seem to ask for 2FA code.

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)

License is MIT

Copyright © 2018-present 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)


TOC is created by https://github.com/muquit/markdown-toc-go on Apr-05-2026

About

mailsend-go is a multi-platform command line tool to send mail via SMTP protocol

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors