diff --git a/README.md b/README.md index 9bb877db..94bcd25e 100644 --- a/README.md +++ b/README.md @@ -214,18 +214,19 @@ The provider acts like any other, i.e. will be registered as `/auth/email/login` For email notify provider, please use `github.com/go-pkgz/auth/provider/sender` package: ```go - sndr := sender.NewEmailClient(sender.EmailParams{ - Host: "email.hostname", - Port: 567, - SMTPUserName: "username", - SMTPPassword: "pass", - StartTLS: true, - From: "notify@email.hostname", - Subject: "subject", - ContentType: "text/html", - Charset: "UTF-8", - }, log.Default()) - authenticator.AddVerifProvider("email", "template goes here", sndr) + sndr := sender.NewEmailClient(sender.EmailParams{ + Host: "email.hostname", + Port: 567, + SMTPUserName: "username", + SMTPPassword: "pass", + StartTLS: true, + InsecureSkipVerify: false, + From: "notify@email.hostname", + Subject: "subject", + ContentType: "text/html", + Charset: "UTF-8", + }, log.Default()) + authenticator.AddVerifProvider("email", "template goes here", sndr) ``` See [that documentation](https://github.com/go-pkgz/email#options) for full options list. diff --git a/go.mod b/go.mod index 8a7923bf..b192cac8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/dghubble/oauth1 v0.7.2 github.com/go-oauth2/oauth2/v4 v4.5.2 - github.com/go-pkgz/email v0.4.1 + github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232 github.com/go-pkgz/repeater v1.1.3 github.com/go-pkgz/rest v1.17.0 github.com/golang-jwt/jwt v3.2.2+incompatible diff --git a/go.sum b/go.sum index 4ca853ba..eec9728a 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ github.com/gavv/httpexpect v2.0.0+incompatible h1:1X9kcRshkSKEjNJJxX9Y9mQ5BRfbxU github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= github.com/go-oauth2/oauth2/v4 v4.5.2 h1:CuZhD3lhGuI6aNLyUbRHXsgG2RwGRBOuCBfd4WQKqBQ= github.com/go-oauth2/oauth2/v4 v4.5.2/go.mod h1:wk/2uLImWIa9VVQDgxz99H2GDbhmfi/9/Xr+GvkSUSQ= -github.com/go-pkgz/email v0.4.1 h1:2vtP2gibsSzqhz6eD5DklSp11m657XEVf17fuXaxMvk= -github.com/go-pkgz/email v0.4.1/go.mod h1:BdxglsQnymzhfdbnncEE72a6DrucZHy6I+42LK2jLEc= +github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232 h1:yfe3v+ai3DYyHl39xCQRB8+uJa1AbaVd1+2m51ZDq6s= +github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232/go.mod h1:BdxglsQnymzhfdbnncEE72a6DrucZHy6I+42LK2jLEc= github.com/go-pkgz/repeater v1.1.3 h1:q6+JQF14ESSy28Dd7F+wRelY4F+41HJ0LEy/szNnMiE= github.com/go-pkgz/repeater v1.1.3/go.mod h1:hVTavuO5x3Gxnu8zW7d6sQBfAneKV8X2FjU48kGfpKw= github.com/go-pkgz/rest v1.17.0 h1:LoBI/lDBMuqwWhOOkc6thM9NnwJO+K9nWvCOjZ7BAgE= diff --git a/provider/sender/email.go b/provider/sender/email.go index 2910c82c..2c773702 100644 --- a/provider/sender/email.go +++ b/provider/sender/email.go @@ -24,13 +24,14 @@ type EmailParams struct { Subject string // Email subject ContentType string // Content type - TLS bool // TLS auth - StartTLS bool // StartTLS auth - Charset string // Character set - LoginAuth bool // LOGIN auth method instead of default PLAIN, needed for Office 365 and outlook.com - SMTPUserName string // username - SMTPPassword string // password - TimeOut time.Duration // TCP connection timeout + TLS bool // TLS auth + StartTLS bool // StartTLS auth + InsecureSkipVerify bool // Skip certificate verification + Charset string // Character set + LoginAuth bool // LOGIN auth method instead of default PLAIN, needed for Office 365 and outlook.com + SMTPUserName string // username + SMTPPassword string // password + TimeOut time.Duration // TCP connection timeout } // NewEmailClient creates email client @@ -69,6 +70,10 @@ func NewEmailClient(emailParams EmailParams, l logger.L) *Email { opts = append(opts, email.STARTTLS(true)) } + if emailParams.InsecureSkipVerify { + opts = append(opts, email.InsecureSkipVerify(true)) + } + sender := email.NewSender(emailParams.Host, opts...) return &Email{EmailParams: emailParams, L: l, sender: sender} diff --git a/provider/sender/email_test.go b/provider/sender/email_test.go index 12b27188..1ef73331 100644 --- a/provider/sender/email_test.go +++ b/provider/sender/email_test.go @@ -38,16 +38,17 @@ func TestEmailSend(t *testing.T) { func TestEmail_New(t *testing.T) { p := EmailParams{ - Host: "127.0.0.2", - From: "from@example.com", - SMTPUserName: "user", - SMTPPassword: "pass", - Subject: "subj", - ContentType: "text/html", - Charset: "UTF-8", - LoginAuth: true, - StartTLS: true, - TLS: true, + Host: "127.0.0.2", + From: "from@example.com", + SMTPUserName: "user", + SMTPPassword: "pass", + Subject: "subj", + ContentType: "text/html", + Charset: "UTF-8", + LoginAuth: true, + StartTLS: true, + TLS: true, + InsecureSkipVerify: true, } e := NewEmailClient(p, logger.Std) assert.Equal(t, p, e.EmailParams)