Gomtp is a cli tool to test smtp settings easily.
You can install the gomtp to Linux or macOS with these commands:
sudo curl -L -o /usr/local/bin/gomtp "https://github.com/burakberkkeskin/gomtp/releases/latest/download/gomtp-$(uname -s)-$(uname -m)" && \
sudo chmod +x /usr/local/bin/gomtpYou can build the gomtp locally, on your own machine.
version=$(git describe --tags --abbrev=0) && \
commitId=$(git --no-pager log -1 --oneline | awk '{print $1}') && \
go build -ldflags "-X gomtp/cmd.version=$version -X gomtp/cmd.commitId=$commitId" -o gomtp -v .- Create a
gomtp.yamlfile anywhre you want. - Take the template from the
gomtp.yaml - There is 4 templates for
mailhog,gmail,yandexandbrevo subjectandbodyis optional.- In the same directory with your configured
gomtp.yaml, rungomtpwith no argument.
❯ gomtp
Email sent successfully!- If your configuration is valid, you will see the "Email sent successfully!" message.
-
You can name the
gomtp.yamlas you wish while creating the configuration. -
If you change the default configuration file name, you can pass the path of the file to the
gomtp.
gomtp --file test.yamlor
gomtp -f test.yamlTo test the gomtp quickly, you can run the mailpit from docker-compose.yml
-
Install the
gomtpby checking the Install section. -
Create a separate directory for config files
mkdir ~/gomtp - Change directory
cd ~/gomtp/ - Download the sample docker-compose.yaml
curl -LO https://raw.githubusercontent.com/burakberkkeskin/gomtp/refs/heads/master/docker-compose.yaml- Download the sample gomtp.yaml configuration.
- The default
gomtp.yamlfile already has been configured for themailpit.
- The default
curl -LO https://raw.githubusercontent.com/burakberkkeskin/gomtp/refs/heads/master/gomtp.yaml- Start the mailpit.
docker compose up -d- Test the gomtp
gomtpEmail sent successfully!
- Open the
mailpitweb ui from http://127.0.0.1:8025 and see the sample email.
If you want to use gomtp to send emails, you can configure a yaml and use it as base. For example, follow the use-case below:
- Create the template file for
gomtp.yamlon your home directory. - Configure the
gomtp.yamlfor your Gmail account in~/gomtp.yamlpath.
vim ~/gomtp.yaml- Configure the
username,password,from. Optionally delete theto,subjectandbodyfields. - Now use
gomtpuse send email to any email address. - With
--bodyflag:
gomtp -f ~/gomtp.yaml --to yourTargetEmailAddress@gmail.com --subject "Test Email From gomtp" --body "test from atlantic server"- With
--body-fileflag:
gomtp -f ~/gomtp.yaml --to yourTargetEmailAddress@gmail.com --subject "Test Email From gomtp" --body-file "~/email-body.log"- With piping a command output:
echo "This is an example command or bash script output" | gomtp -f ~/gomtp.yaml --to yourTargetEmailAddress@gmail.com --subject "Test Email From gomtp"- Define a version.
export gomtpVersion=v1.4.0- You should create a release branch from the master
git checkout master && git pull && \
git checkout -b release/${gomtpVersion}- Tag the commit
git tag --sign ${gomtpVersion} -m "Added verifyCertificate and example commands."- Push the release branch and tags
git push && git push --tags- Before run the tests, run the docker compose file.
docker compose up -d- You can run e2e tests to ensure application stability.
go test -p 1 ./cmd/- Check the test coverage:
go test -p 1 ./cmd/ -coverprofile=coverage.out- You can see covered lines with html report:
go test -p 1 ./cmd/ -coverprofile=coverage.out -test.coverprofile ./c.out && \
go tool cover -html=c.out