Very simple Go app to send notification email. Usually invoked by scripts. A set of standard emails can be built using the JSON formatted configuration file. So several notifications emails can be pre-defined and used accordingly.
Each email will have a JSON file and can be stored anywhere. If a param with the
path/filename
is not passed, the default app path/files folder will be used to
search the named JSON file.
Most of the config variables may be set via app param. Attention: calling params will overide JSON file configs.
Default config file is ./mailsender.json
The message
can be passed into the body
template is this has a %s or %d.
Format file: JSON structured:
{
"app_name": "Alpha",
"app_name": "monit",
"secure": true,
"smtp_host": "mailtrap.io",
"smtp_port": 2525,
"smtp_email": "sender@example.com",
"smtp_username": "smtpusername123",
"smtp_password": "123456",
"email_address": "me@example.com",
"subject": "lift-off notification",
"body": "%s ready for lift-off",
"message": "Eagle 3",
"log": true,
"log_file": "mailsender_1.log",
}
$ mailsender -p /path/to/file -f filename.json
- configs: (string) path to the JSON configs file
- server_name: (string) server name that triggers the notification
- app_name: (string) app name that triggers the notification
- secure: (bool) http vs https.
- smtp_host: (string) the hostname of the email provider
- smtp_port: (int) the port of the smtp host
- smtp_email: (string) the email of the sender (from header)
- smtp_username: (string) the username for the smtp auth
- smtp_password: (string) the password for the smtp auth
- email_address: (string) email to receive the alerts.
- subject: (string) a default subject for the email
- body: (string) a default body message, accepting [%s|%d|...] params
- message: (string) message passed into the app (composing the body)
- log: (bool) log ?
- log_file: (string) # file to append the log.
For testing purposes, one can define a fake smtp.SendMail function.
If you are building on OSX for Linux usage, make sure your Go e prepared to generate binaries for other architectures. To enable it for Linux:
$ cd $GOROOT/src
$ GOOS=linux GOARCH=386 ./make.bash
Then to generate a linux specific binary:
$ GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o mailsender.linux mailsender.go