Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ With chatz, you can streamline your notification processes across multiple platf
- Telegram: [Read documentation](docs/telegram.md)
- Discord: [Read documentation](docs/discord.md)
- Redis: [Read documentation](docs/redis.md)
- SMTP: [Read documentation](docs/smtp.md)

## Installation
Download and install executable binary from GitHub releases page.
Expand Down Expand Up @@ -113,6 +114,47 @@ CONNECTION_URL=<redis-connection-url>
CHANNEL_ID=<redis-publish-channel>
```

- Config for smtp provider with TLS
```ini
[default]
PROVIDER=smtp
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USE_TLS=true
SMTP_USER=<[email protected]>
SMTP_PASSWORD=<app-password>
SMTP_SUBJECT=<Your subject>
SMTP_FROM=<[email protected]>
SMTP_TO=<[email protected],[email protected]>
```

- Config for smtp provider with STARTTLS
```ini
[default]
PROVIDER=smtp
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USE_STARTTLS=true
SMTP_USER=<[email protected]>
SMTP_PASSWORD=<app-password>
SMTP_SUBJECT=<Your subject>
SMTP_FROM=<[email protected]>
SMTP_TO=<[email protected],[email protected]>
```

- Config for smtp provider without encryption
```ini
[default]
PROVIDER=smtp
SMTP_HOST=smtp.yourmailserver.com
SMTP_PORT=25
SMTP_USER=<[email protected]>
SMTP_PASSWORD=<app-password>
SMTP_SUBJECT=<Your subject>
SMTP_FROM=<[email protected]>
SMTP_TO=<[email protected],[email protected]>
```

### System Environment Support
Chatz also support system environment variable. To use system environment variable then use `--from-env` or `-e` flag.
Name of the environment variable is same as `chatz.ini` config key, for example `export PROVIDER=slack`.
Expand Down
21 changes: 15 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ package config

// Environment
type Config struct {
Provider string
WebHookURL string
Token string
ChannelId string
ChatId string
ConnectionURL string
Provider string
WebHookURL string
Token string
ChannelId string
ChatId string
ConnectionURL string
SMTPHost string
SMTPPort string
UseTLS bool
UseSTARTTLS bool
SMTPUser string
SMTPPassword string
SMTPSubject string
SMTPFrom string
SMTPTo string
}
11 changes: 6 additions & 5 deletions constants/common.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package constants

const (
PROVIDER_SLACK="slack"
PROVIDER_DISCORD="discord"
PROVIDER_TELEGRAM="telegram"
PROVIDER_GOOGLE="google"
PROVIDER_REDIS="redis"
PROVIDER_SLACK = "slack"
PROVIDER_DISCORD = "discord"
PROVIDER_TELEGRAM = "telegram"
PROVIDER_GOOGLE = "google"
PROVIDER_REDIS = "redis"
PROVIDER_SMTP = "smtp"
)
59 changes: 59 additions & 0 deletions docs/smtp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SMTP with Gmail

This document explains how to configure SMTP with Gmail, including creating an App Password, and understanding TLS/STARTTLS and encryption options.


## 1. Creating an App Password

Gmail requires an "App Password" for less secure apps accessing your account. This is a more secure alternative to using your regular Gmail password directly.

1. Go to your [Google account security settings](https://myaccount.google.com/security).
2. Scroll down to "Signing in to Google" and click "App Passwords".
3. Select "Mail" as the app and "Other (Custom name)" as the device. Give it a descriptive name (e.g., "My SMTP App").
4. Click "Generate". A new password will be displayed. **Copy this password immediately; you won't be able to see it again.**

## 2. SMTP Server Settings

* **Server:** `smtp.gmail.com`
* **Port:**
* **STARTTLS:** 587 (Recommended)
* **TLS:** 465
* **No Encryption (Insecure - Avoid):** 25
* **Username:** Your full Gmail address (e.g., `[email protected]`)
* **Password:** The App Password you generated.


## 3. TLS/STARTTLS and Encryption

* **TLS (Transport Layer Security) / STARTTLS:** These are encryption protocols that secure the connection between your email client and the SMTP server. They encrypt your email messages and prevent eavesdropping. **Using TLS/STARTTLS is strongly recommended.** Many email clients support STARTTLS, initiating encryption during the connection process.


* **No Encryption:** Sending emails without encryption is highly discouraged. Your email, including the subject, body, and any attachments, could be intercepted by malicious actors. Avoid this unless absolutely necessary, and only with trusted parties.



## 4. Example Configuration (Illustrative - adapt to your email client)


This is a generic example; the exact settings will depend on your email client (e.g., Outlook, Thunderbird). Refer to your email client's documentation for specific instructions.


```
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USE_STARTTLS=true
```

Remember to replace placeholders with your actual information.

## 5. Troubleshooting


If you encounter issues, check:

* **Correct App Password:** Verify you copied the correct App Password.
* **Firewall Settings:** Ensure your firewall isn't blocking outgoing connections on port 587 (or 465 if using no encryption).
* **Email Client Configuration:** Double-check all server settings in your email client.

Using an App Password is crucial for securing your Gmail account when using SMTP. Always prioritize using TLS/STARTTLS encryption for the security of your emails.
```
178 changes: 88 additions & 90 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,104 @@ import (
)

var (
AppVersion = "v0.0.1"
CommitHash = "unknown"
BuildDate = "unknown"
AppVersion = "v0.0.1"
CommitHash = "unknown"
BuildDate = "unknown"
)

func main() {

var version bool
var profile string
var threadId string
var output bool
var fromEnv bool

app := cli.NewApp()
app.Name = "chatz"
app.Description = "chatz is a versatile messaging app designed to send notifications to Google Chat, Slack, Discord, Telegram and Redis."
app.Flags = []cli.Flag {
&cli.BoolFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Print output to stdout",
Destination: &output,
},
&cli.StringFlag{
Name: "profile",
Aliases: []string{"p"},
Value: "default",
Usage: "Profile from .chatz.ini",
Destination: &profile,
},
&cli.StringFlag{
Name: "thread-id",
Aliases: []string{"t"},
Value: "",
Usage: "Thread ID for reply to a message",
Destination: &threadId,
},
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the version number",
Destination: &version,
},
&cli.BoolFlag{
Name: "from-env",
Aliases: []string{"e"},
Usage: "To use config from environment variables",
Destination: &fromEnv,
},
}
app.Action = func(ctx *cli.Context) error {
if version {
fmt.Println("chatz version: ", AppVersion)
fmt.Println("Commit Hash: ", CommitHash)
fmt.Println("Build Date: ", BuildDate)
return nil
}
var version bool
var profile string
var threadId string
var output bool
var fromEnv bool

app := cli.NewApp()
app.Name = "chatz"
app.Description = "chatz is a versatile messaging app designed to send notifications to Google Chat, Slack, Discord, Telegram and Redis."
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Print output to stdout",
Destination: &output,
},
&cli.StringFlag{
Name: "profile",
Aliases: []string{"p"},
Value: "default",
Usage: "Profile from .chatz.ini",
Destination: &profile,
},
&cli.StringFlag{
Name: "thread-id",
Aliases: []string{"t"},
Value: "",
Usage: "Thread ID for reply to a message",
Destination: &threadId,
},
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the version number",
Destination: &version,
},
&cli.BoolFlag{
Name: "from-env",
Aliases: []string{"e"},
Usage: "To use config from environment variables",
Destination: &fromEnv,
},
}
app.Action = func(ctx *cli.Context) error {
if version {
fmt.Println("chatz version: ", AppVersion)
fmt.Println("Commit Hash: ", CommitHash)
fmt.Println("Build Date: ", BuildDate)
return nil
}

var message string
if ctx.Args().Len() == 0 {
fmt.Println("Please provide a message.")
return nil
}
for i, a := range ctx.Args().Slice() {
if i == 0 {
message = a
continue
}
message = fmt.Sprintf("%s %s", message, a)
}

var message string
if ctx.Args().Len() == 0 {
fmt.Println("Please provide a message.")
return nil
}
for i, a := range ctx.Args().Slice() {
if i == 0 {
message = a
continue
}
message = fmt.Sprintf("%s %s",message, a)
}

env, err := utils.LoadEnv(profile, fromEnv)
if err!=nil {
return nil
}
provider, err := providers.NewProvider(env)
if err!=nil {
fmt.Println(err.Error())
return nil
}
env, err := utils.LoadEnv(profile, fromEnv)
if err != nil {
return nil
}

if len(threadId) > 0 {
res, _ := provider.Reply(threadId, message)
if output {
fmt.Println(res)
}
return nil
}
res, _ := provider.Post(message)
if output {
fmt.Println(res)
}
provider, err := providers.NewProvider(env)
if err != nil {
fmt.Println(err.Error())
return nil
}

return nil
}
if len(threadId) > 0 {
res, _ := provider.Reply(threadId, message)
if output {
fmt.Println(res)
}
return nil
}
res, err := provider.Post(message)
if output {
fmt.Println(res)
}
return nil
}

if err := app.Run(os.Args); err != nil {
if err := app.Run(os.Args); err != nil {
panic(err)
}

}

16 changes: 16 additions & 0 deletions man/chatz.1
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ CONNECTION_URL=<redis-url>
CHANNEL_ID=<redis-channel>
.fi

.TP
Configuration for SMTP.

.nf
[default]
PROVIDER=smtp
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USE_STARTTLS=true
SMTP_USER=<[email protected]>
SMTP_PASSWORD=<app-password>
SMTP_SUBJECT=<Your subject>
SMTP_FROM=<[email protected]>
SMTP_TO=<[email protected],[email protected]>
.fi

.TP
Ensure that each service is properly configured with valid tokens and webhook URLs.

Expand Down
Loading
Loading