Skip to content

Commit 4e5716e

Browse files
sukhwinder33445julianbrost
authored andcommitted
channel/email: Make fields required instead of setting default values
1 parent 63ae2d2 commit 4e5716e

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

cmd/channel/email/main.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/jhillyerd/enmime"
1515
"net"
1616
"net/mail"
17-
"os"
18-
"os/user"
1917
)
2018

2119
const (
@@ -103,30 +101,8 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
103101
return fmt.Errorf("failed to load config: %s %w", jsonStr, err)
104102
}
105103

106-
if ch.Host == "" {
107-
ch.Host = "localhost"
108-
}
109-
110-
if ch.Port == "" {
111-
ch.Port = "25"
112-
}
113-
114-
if ch.SenderMail == "" {
115-
hostname, err := os.Hostname()
116-
if err != nil {
117-
return fmt.Errorf("failed to get the OS hostname: %w", err)
118-
}
119-
120-
usr, err := user.Current()
121-
if err != nil {
122-
return fmt.Errorf("failed to get the OS current user: %w", err)
123-
}
124-
125-
ch.SenderMail = usr.Username + "@" + hostname
126-
}
127-
128-
if ch.User == "" {
129-
ch.User = ch.SenderMail
104+
if (ch.User == "") != (ch.Password == "") {
105+
return fmt.Errorf("user and password fields must both be set or empty")
130106
}
131107

132108
return nil
@@ -143,25 +119,28 @@ func (ch *Email) GetInfo() *plugin.Info {
143119
},
144120
},
145121
{
146-
Name: "sender_mail",
147-
Type: "string",
122+
Name: "sender_mail",
123+
Type: "string",
124+
Required: true,
148125
Label: map[string]string{
149126
"en_US": "Sender Address",
150127
"de_DE": "Absenderadresse",
151128
},
152129
Default: "[email protected]",
153130
},
154131
{
155-
Name: "host",
156-
Type: "string",
132+
Name: "host",
133+
Type: "string",
134+
Required: true,
157135
Label: map[string]string{
158136
"en_US": "SMTP Host",
159137
"de_DE": "SMTP Host",
160138
},
161139
},
162140
{
163-
Name: "port",
164-
Type: "number",
141+
Name: "port",
142+
Type: "number",
143+
Required: true,
165144
Label: map[string]string{
166145
"en_US": "SMTP Port",
167146
"de_DE": "SMTP Port",

0 commit comments

Comments
 (0)