From a33aba3534e6cf90ee3596c931e72e38df066da5 Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 11 Feb 2022 14:35:57 -0600 Subject: [PATCH] make TLS with param to simplify conditional usage --- email_test.go | 4 ++-- options.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/email_test.go b/email_test.go index 8dd1f7e..1587be1 100644 --- a/email_test.go +++ b/email_test.go @@ -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()) @@ -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: "from@example.com", To: []string{"to@example.com"}, diff --git a/options.go b/options.go index 48b4d2c..3cc1b86 100644 --- a/options.go +++ b/options.go @@ -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