Skip to content

Commit

Permalink
fix: sync with master to resolve conflicts
Browse files Browse the repository at this point in the history
Merge branch 'master' into feat/login-auth
  • Loading branch information
gurza committed Sep 29, 2022
2 parents 752004d + 66a670a commit 877bf78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ To send email user need to create a sender first and then use `Send` method. The
To []string // From email field
Subject string // Email subject
UnsubscribeLink string // POST, https://support.google.com/mail/answer/81126 -> "Use one-click unsubscribe"
InReplyTo string // Identifier for email group (category), used for email grouping
Attachments []string // Attachments path
InlineImages []string // Embedding directly to email body. Autogenerated Content-Id (cid) equals to file name
}
Expand All @@ -60,7 +61,7 @@ See [go docs](https://pkg.go.dev/github.com/go-pkgz/email#Sender.Send) for `Send
- Custom SMTP client (`smtp.Client` from stdlib) can be set by user with `SMTP` option. In this case it will be used instead of making a new smtp client internally.
- Logger can be set with `Log` option. It should implement `email.Logger` interface with a single `Logf(format string, args ...interface{})` method. By default, "no logging" internal logger is used. This interface is compatible with the `go-pkgz/lgr` logger.
- The library has no external dependencies, except for testing. It uses the stdlib `net/smtp` package.
- SSL/TLS supported with `TLS` option. Pls note: this is not the same as `STARTTLS` (not supported) which is usually on port 587 vs SSL/TLS on port 465.
- SSL/TLS supported with `TLS` option (usually on port 465) as well as with `STARTTLS` (usually on port 587).

## limitations

Expand Down
5 changes: 5 additions & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Params struct {
To []string // From email field
Subject string // Email subject
UnsubscribeLink string // POST, https://support.google.com/mail/answer/81126 -> "Use one-click unsubscribe"
InReplyTo string // Identifier for email group (category), used for email grouping
Attachments []string // Attachments path
InlineImages []string // InlineImages images path
}
Expand Down Expand Up @@ -232,6 +233,10 @@ func (em *Sender) buildMessage(text string, params Params) (message string, err
message = addHeader(message, "List-Unsubscribe", "<"+params.UnsubscribeLink+">")
}

if params.InReplyTo != "" {
message = addHeader(message, "In-reply-to", "<"+params.InReplyTo+">")
}

withAttachments := len(params.Attachments) > 0
withInlineImg := len(params.InlineImages) > 0

Expand Down
3 changes: 2 additions & 1 deletion email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,11 @@ func TestEmail_buildMessageWithMIME(t *testing.T) {
To: []string{"to@example.com"},
Subject: "non-ascii symbols: Привет",
UnsubscribeLink: "https://example.com/unsubscribe",
InReplyTo: "uuid@example.com",
})
require.NoError(t, err)
assert.Contains(t, msg, "Content-Transfer-Encoding: quoted-printable\nContent-Type: text/html; charset=\"UTF-8\"", msg)
assert.Contains(t, msg, "From: from@example.com\nTo: to@example.com\nSubject: =?utf-8?b?bm9uLWFzY2lpIHN5bWJvbHM6INCf0YDQuNCy0LXRgg==?=\nList-Unsubscribe-Post: List-Unsubscribe=One-Click\nList-Unsubscribe: <https://example.com/unsubscribe>\nMIME-version: 1.0", msg)
assert.Contains(t, msg, "From: from@example.com\nTo: to@example.com\nSubject: =?utf-8?b?bm9uLWFzY2lpIHN5bWJvbHM6INCf0YDQuNCy0LXRgg==?=\nList-Unsubscribe-Post: List-Unsubscribe=One-Click\nList-Unsubscribe: <https://example.com/unsubscribe>\nIn-reply-to: <uuid@example.com>\nMIME-version: 1.0", msg)
assert.Contains(t, msg, "\n\nthis is a test\r\n12345\r\n", msg)
assert.Contains(t, msg, "Date: ", msg)
}
Expand Down

0 comments on commit 877bf78

Please sign in to comment.