Skip to content

Commit

Permalink
Merge pull request #3 from safderun/feature/1
Browse files Browse the repository at this point in the history
#1 Added Custom Configuration File Path
  • Loading branch information
burakberkkeskin authored Dec 23, 2023
2 parents 881961c + 924c299 commit 70057bb
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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
```
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ 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)
fmt.Printf("gomtp version %s, %s", version, commitId)
}

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)
}
Expand Down
63 changes: 63 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
##### Mailhog Example #####
#
username: ''
password: ''
from: '[email protected]'
to: '[email protected]'
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: '[email protected]'
# password: 'appPassword'
# from: '[email protected]'
# to: '[email protected]'
# 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: '[email protected]'
# password: 'superSecretPassword'
# from: '[email protected]'
# to: '[email protected]'
# 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: '[email protected]'
# password: 'superSecretPassword'
# from: '[email protected]'
# to: '[email protected]'
# 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

0 comments on commit 70057bb

Please sign in to comment.