Skip to content

Commit d38c149

Browse files
committed
Docs
1 parent fc3624c commit d38c149

7 files changed

+55
-19
lines changed

docs/publish.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2941,11 +2941,17 @@ format is:
29412941
ntfy-$topic@ntfy.sh
29422942
```
29432943

2944-
If [access control](config.md#access-control) is enabled, and the target topic does not support anonymous writes, e-mail publishing won't work without providing an authorized access token. That will change the format of the e-mail's recipient address to
2944+
If [access control](config.md#access-control) is enabled, and the target topic does not support anonymous writes, e-mail publishing won't work
2945+
without providing an authorized access token or using SMTP AUTH PLAIN.
2946+
2947+
If you use [access tokens](#access-tokens), that will change the format of the e-mail's recipient address to
29452948
```
29462949
ntfy-$topic+$token@ntfy.sh
29472950
```
29482951

2952+
To use [username/password](https://docs.ntfy.sh/publish/#username-password), you can use SMTP PLAIN auth when authenticating
2953+
to the ntfy server.
2954+
29492955
As of today, e-mail publishing only supports adding a [message title](#message-title) (the e-mail subject). Tags, priority,
29502956
delay and other features are not supported (yet). Here's an example that will publish a message with the
29512957
title `You've Got Mail` to topic `sometopic` (see [ntfy.sh/sometopic](https://ntfy.sh/sometopic)):

docs/releases.md

+17
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,23 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
13731373

13741374
## Not released yet
13751375

1376+
### ntfy server v2.12.0 (UNRELEASED)
1377+
1378+
**Features:**
1379+
1380+
* Add username/password auth to email publishing ([#1164](https://github.com/binwiederhier/ntfy/pull/1164), thanks to [@bishtawi](https://github.com/bishtawi))
1381+
1382+
**Bug fixes + maintenance:**
1383+
1384+
* Add `Date` header to outgoing emails to avoid rejection ([#1141](https://github.com/binwiederhier/ntfy/pull/1141), thanks to [pcouy](https://github.com/pcouy))
1385+
1386+
**Documentation:**
1387+
1388+
* Various docs updates ([](https://github.com/binwiederhier/ntfy/pull/1161), thanks to [@OneWeekNotice](https://github.com/OneWeekNotice))
1389+
* Typo in config docs ([#1177](https://github.com/binwiederhier/ntfy/pull/1177), thanks to [@hoho4190](https://github.com/hoho4190))
1390+
* Typo in CLI docs ([#1172](https://github.com/binwiederhier/ntfy/pull/1172), thanks to [@anirvan](https://github.com/anirvan))
1391+
* Correction about MacroDroid ([](https://github.com/binwiederhier/ntfy/pull/1137), thanks to [@ShlomoCode](https://github.com/ShlomoCode))
1392+
13761393
### ntfy Android app v1.16.1 (UNRELEASED)
13771394

13781395
**Features:**

server/server_test.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ func TestServer_PublishEmailNoMailer_Fail(t *testing.T) {
12771277
func TestServer_PublishAndExpungeTopicAfter16Hours(t *testing.T) {
12781278
t.Parallel()
12791279
s := newTestServer(t, newTestConfig(t))
1280+
defer s.messageCache.Close()
12801281

12811282
subFn := func(v *visitor, msg *message) error {
12821283
return nil
@@ -1288,13 +1289,22 @@ func TestServer_PublishAndExpungeTopicAfter16Hours(t *testing.T) {
12881289
})
12891290
require.Equal(t, 200, response.Code)
12901291
waitFor(t, func() bool {
1292+
s.mu.Lock()
1293+
tp, exists := s.topics["mytopic"]
1294+
s.mu.Unlock()
1295+
if !exists {
1296+
return false
1297+
}
12911298
// .lastAccess set in t.Publish() -> t.Keepalive() in Goroutine
1292-
s.topics["mytopic"].mu.RLock()
1293-
defer s.topics["mytopic"].mu.RUnlock()
1294-
return s.topics["mytopic"].lastAccess.Unix() >= time.Now().Unix()-2 &&
1295-
s.topics["mytopic"].lastAccess.Unix() <= time.Now().Unix()+2
1299+
tp.mu.RLock()
1300+
defer tp.mu.RUnlock()
1301+
return tp.lastAccess.Unix() >= time.Now().Unix()-2 &&
1302+
tp.lastAccess.Unix() <= time.Now().Unix()+2
12961303
})
12971304

1305+
// Hack!
1306+
time.Sleep(time.Second)
1307+
12981308
// Topic won't get pruned
12991309
s.execManager()
13001310
require.NotNil(t, s.topics["mytopic"])

server/smtp_sender.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func formatMail(baseURL, senderIP, from, to string, m *message) (string, error)
110110
if trailer != "" {
111111
message += "\n\n" + trailer
112112
}
113-
date := time.Unix(m.Time, 0).Format(time.RFC1123Z)
113+
date := time.Unix(m.Time, 0).UTC().Format(time.RFC1123Z)
114114
subject = mime.BEncoding.Encode("utf-8", subject)
115115
body := `From: "{shortTopicURL}" <{from}>
116116
To: {to}

server/smtp_sender_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func TestFormatMail_Basic(t *testing.T) {
1515
})
1616
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
1717
To: phil@example.com
18+
Date: Fri, 24 Dec 2021 21:43:24 +0000
1819
Subject: A simple message
1920
Content-Type: text/plain; charset="utf-8"
2021
@@ -36,6 +37,7 @@ func TestFormatMail_JustEmojis(t *testing.T) {
3637
})
3738
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
3839
To: phil@example.com
40+
Date: Fri, 24 Dec 2021 21:43:24 +0000
3941
Subject: =?utf-8?b?8J+YgCBBIHNpbXBsZSBtZXNzYWdl?=
4042
Content-Type: text/plain; charset="utf-8"
4143
@@ -57,6 +59,7 @@ func TestFormatMail_JustOtherTags(t *testing.T) {
5759
})
5860
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
5961
To: phil@example.com
62+
Date: Fri, 24 Dec 2021 21:43:24 +0000
6063
Subject: A simple message
6164
Content-Type: text/plain; charset="utf-8"
6265
@@ -80,6 +83,7 @@ func TestFormatMail_JustPriority(t *testing.T) {
8083
})
8184
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
8285
To: phil@example.com
86+
Date: Fri, 24 Dec 2021 21:43:24 +0000
8387
Subject: A simple message
8488
Content-Type: text/plain; charset="utf-8"
8589
@@ -103,6 +107,7 @@ func TestFormatMail_UTF8Subject(t *testing.T) {
103107
})
104108
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
105109
To: phil@example.com
110+
Date: Fri, 24 Dec 2021 21:43:24 +0000
106111
Subject: =?utf-8?b?IDo6IEEgbm90IHNvIHNpbXBsZSB0aXRsZSDDtsOkw7zDnyDCoUhvbGEsIHNl?= =?utf-8?b?w7FvciE=?=
107112
Content-Type: text/plain; charset="utf-8"
108113
@@ -126,6 +131,7 @@ func TestFormatMail_WithAllTheThings(t *testing.T) {
126131
})
127132
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
128133
To: phil@example.com
134+
Date: Fri, 24 Dec 2021 21:43:24 +0000
129135
Subject: =?utf-8?b?4pqg77iPIPCfkoAgT2ggbm8g8J+ZiCBUaGlzIGlzIGEgbWVzc2FnZSBhY3Jv?= =?utf-8?b?c3MgbXVsdGlwbGUgbGluZXM=?=
130136
Content-Type: text/plain; charset="utf-8"
131137

server/smtp_server.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,18 @@ func (b *smtpBackend) Counts() (total int64, success int64, failure int64) {
7070

7171
// smtpSession is returned after EHLO.
7272
type smtpSession struct {
73-
backend *smtpBackend
74-
conn *smtp.Conn
75-
topic string
76-
token string
77-
mu sync.Mutex
78-
basic_auth string
73+
backend *smtpBackend
74+
conn *smtp.Conn
75+
topic string
76+
token string // If email address contains token, e.g. topic+token@domain
77+
basicAuth string // If SMTP AUTH PLAIN was used
78+
mu sync.Mutex
7979
}
8080

8181
func (s *smtpSession) AuthPlain(username, password string) error {
8282
logem(s.conn).Field("smtp_username", username).Debug("AUTH PLAIN (with username %s)", username)
83-
basic_auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password)))
8483
s.mu.Lock()
85-
s.basic_auth = basic_auth
84+
s.basicAuth = base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password)))
8685
s.mu.Unlock()
8786
return nil
8887
}
@@ -203,8 +202,8 @@ func (s *smtpSession) publishMessage(m *message) error {
203202
}
204203
if s.token != "" {
205204
req.Header.Add("Authorization", "Bearer "+s.token)
206-
} else if s.basic_auth != "" {
207-
req.Header.Add("Authorization", "Basic "+s.basic_auth)
205+
} else if s.basicAuth != "" {
206+
req.Header.Add("Authorization", "Basic "+s.basicAuth)
208207
}
209208
rr := httptest.NewRecorder()
210209
s.backend.handler(rr, req)
@@ -222,7 +221,7 @@ func (s *smtpSession) Reset() {
222221

223222
func (s *smtpSession) Logout() error {
224223
s.mu.Lock()
225-
s.basic_auth = ""
224+
s.basicAuth = ""
226225
s.mu.Unlock()
227226
return nil
228227
}

server/topic_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
)
1111

1212
func TestTopic_CancelSubscribersExceptUser(t *testing.T) {
13-
t.Parallel()
14-
1513
subFn := func(v *visitor, msg *message) error {
1614
return nil
1715
}

0 commit comments

Comments
 (0)