From 924c2992f045c903593a1b607312d08d20018725 Mon Sep 17 00:00:00 2001 From: safderun Date: Sat, 23 Dec 2023 13:29:24 +0300 Subject: [PATCH] added custom file path --- README.md | 23 +++++++-- docker-compose.yml => docker-compose.yaml | 0 gomtp.yml => gomtp.yaml | 0 main.go | 8 +-- test.yml | 63 +++++++++++++++++++++++ 5 files changed, 87 insertions(+), 7 deletions(-) rename docker-compose.yml => docker-compose.yaml (100%) rename gomtp.yml => gomtp.yaml (100%) create mode 100644 test.yml diff --git a/README.md b/README.md index 493fcd4..0e95605 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ sudo chmod +x /usr/local/bin/gomtp ## Usage -- Create a `gomtp.yml` file anywhre you want. -- Take the template from the `gomtp.yml` +- Create a `gomtp.yaml` file anywhre you want. +- Take the template from the `gomtp.yaml` - There is 4 templates for `mailhog`, `gmail`, `yandex` and `brevo` - `subject` and `body` is optional. -- In the same directory with your configured `gomtp.yml`, run `gomtp` with no argument. +- In the same directory with your configured `gomtp.yaml`, run `gomtp` with no argument. ```bash ❯ gomtp @@ -24,6 +24,16 @@ Email sent successfully! - If your configuration is valid, you will see the "Email sent successfully!" message. +## Custom Gomtp Yaml Path + +- You can name the `gomtp.yaml` as 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`. + +```bash +gomtp test.yaml +``` + ## Sample SMTP For Testing - To test the `gomtp` quickly, you can run the `mailhog` from `docker-compose.yml` @@ -32,6 +42,11 @@ Email sent successfully! docker compose up -d ``` -- Configure `gomtp.yml` +- Configure `gomtp.yaml` + - The default `gomtp.yaml` file has been configured for the mailhog. - Open the `mailhog` web ui from http://127.0.0.1:8025 - Run the `gomtp`. + +```bash +gomtp +``` diff --git a/docker-compose.yml b/docker-compose.yaml similarity index 100% rename from docker-compose.yml rename to docker-compose.yaml diff --git a/gomtp.yml b/gomtp.yaml similarity index 100% rename from gomtp.yml rename to gomtp.yaml diff --git a/main.go b/main.go index 1574c82..6061f1d 100644 --- a/main.go +++ b/main.go @@ -25,8 +25,9 @@ type EmailConfig struct { Body string `yaml:"body"` } -var version = "abcd" +var version string var commitId string +var gomtpYamlFilePath = "gomtp.yaml" func checkVersion() { fmt.Println(version) @@ -34,16 +35,17 @@ func checkVersion() { } func main() { - if len(os.Args) > 1 { if os.Args[1] == "--version" { checkVersion() os.Exit(0) + } else { + gomtpYamlFilePath = os.Args[1] } } // Read the YAML configuration file - configFile, err := os.ReadFile("gomtp.yml") + configFile, err := os.ReadFile(gomtpYamlFilePath) if err != nil { log.Fatal(err) } diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..d181d74 --- /dev/null +++ b/test.yml @@ -0,0 +1,63 @@ +##### Mailhog Example ##### +# +username: '' +password: '' +from: 'from@example.com' +to: 'to@example.com' +host: '127.0.0.1' +port: 1025 +ssl: false +tls: false +auth: 'NO' +subject: 'Testing Email' +body: | + this is line 1 + This is line 2 + +##### Gmail Example ##### +# +# username: 'from@gmail.com' +# password: 'appPassword' +# from: 'from@gmail.com' +# to: 'to@example.com' +# host: 'smtp.gmail.com' +# port: 587 +# ssl: false +# tls: true +# auth: 'LOGIN' +# subject: 'Testing Email' +# body: | +# this is line 1 +# This is line 2 + +##### Yandex Example ##### +# +# username: 'example@yandex.com' +# password: 'superSecretPassword' +# from: 'example@yandex.com' +# to: 'example@test.com' +# host: 'smtp.yandex.com' +# port: 465 +# ssl: true +# tls: false +# auth: 'LOGIN' +# subject: 'Testing Email' +# body: | +# this is line 1 +# This is line 2 + +##### Brevo Example ##### +# +# username: 'user@example.com' +# password: 'superSecretPassword' +# from: 'from@example.com' +# to: 'to@example.com' +# host: 'smtp-relay.brevo.com' +# port: 587 +# ssl: false +# tls: true +# auth: 'LOGIN' +# subject: 'Testing Email' +# body: | +# this is line 1 +# This is line 2