Skip to content

Commit

Permalink
make TLS with param to simplify conditional usage
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Feb 11, 2022
1 parent 2529413 commit a33aba3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestEmail_New(t *testing.T) {
}}

s := NewSender("localhost", ContentType("text/html"), Port(123),
TLS, Auth("user", "pass"), TimeOut(time.Second), Log(logger), Charset("blah"))
TLS(true), Auth("user", "pass"), TimeOut(time.Second), Log(logger), Charset("blah"))
require.NotNil(t, s)
assert.Equal(t, "[INFO] new email sender created with host: localhost:123, tls: true, username: \"user\", timeout: 1s, content type: \"text/html\", charset: \"blah\"",
logBuff.String())
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestEmail_SendFailedMakeClient(t *testing.T) {
}

{
s := NewSender("127.0.0.1", Port(225), TLS, TimeOut(time.Millisecond*200))
s := NewSender("127.0.0.1", Port(225), TLS(true), TimeOut(time.Millisecond*200))
err := s.Send("some text", Params{
From: "[email protected]",
To: []string{"[email protected]"},
Expand Down
8 changes: 5 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func Charset(charset string) Option {
}
}

// TLS enables TLS support
func TLS(s *Sender) {
s.tls = true
//TLS enables TLS support
func TLS(enabled bool) Option {
return func(s *Sender) {
s.tls = enabled
}
}

// Auth sets smtp username and password
Expand Down

0 comments on commit a33aba3

Please sign in to comment.