Skip to content

Commit

Permalink
add Sender.String() #6
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Apr 24, 2022
1 parent f81e515 commit c606c5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func (em *Sender) Send(text string, params Params) error {
return nil
}

func (em *Sender) String() string {
return fmt.Sprintf("smtp://%s:%d, auth:%v, tls:%v, starttls:%v timeout:%v, content-type:%q, charset:%q",
em.host, em.port, em.smtpUserName != "", em.tls, em.starttls, em.timeOut, em.contentType, em.contentCharset)
}

func (em *Sender) client() (c *smtp.Client, err error) {
srvAddress := fmt.Sprintf("%s:%d", em.host, em.port)
tlsConf := &tls.Config{
Expand Down
13 changes: 12 additions & 1 deletion email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ func TestWriteBodyFail(t *testing.T) {
require.Error(t, err)
}

func TestSender_String(t *testing.T) {
e := NewSender("localhost", ContentType("text/html"), Port(2525), Auth("user", "pass"))
assert.Equal(t, `smtp://localhost:2525, auth:true, tls:false, starttls:false timeout:30s, content-type:"text/html", charset:"UTF-8"`,
e.String())

e = NewSender("localhost", ContentType("text/html"), Port(2525), TLS(true),
STARTTLS(true), TimeOut(10*time.Second))
assert.Equal(t, `smtp://localhost:2525, auth:false, tls:true, starttls:true timeout:10s, content-type:"text/html", charset:"UTF-8"`,
e.String())
}

// uncomment to debug with real smtp server
// func TestSendIntegration(t *testing.T) {
// client := NewSender("localhost", ContentType("text/html"), Port(2525))
Expand All @@ -492,7 +503,7 @@ func TestWriteBodyFail(t *testing.T) {
// InlineImages: []string{"testdata/image.jpg"},
// })
// require.NoError(t, err)
//}
// }

type fakeWriterCloser struct {
buff *bytes.Buffer
Expand Down

0 comments on commit c606c5c

Please sign in to comment.