Skip to content

Commit cbae3c3

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
optimize email template for gmail
1 parent 8a5e036 commit cbae3c3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

email/templates.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,23 @@ func (s *Sender) formatNotificationBody(sub *notifier.Subscription, thread *noti
5151
b.WriteString("</style>\n</head>\n<body>\n")
5252

5353
// Render each post - no redundant header
54-
for _, post := range posts {
55-
b.WriteString("<div class=\"post\">\n")
54+
for i, post := range posts {
55+
// Use inline styles for first/last posts to ensure Gmail compatibility (it doesn't support :first-of-type/:last-of-type)
56+
isFirst := i == 0
57+
isLast := i == len(posts)-1
58+
59+
if isFirst && isLast {
60+
// Single post: no top padding, no bottom border
61+
b.WriteString("<div class=\"post\" style=\"padding-top: 0; border-bottom: none; padding-bottom: 0;\">\n")
62+
} else if isFirst {
63+
// First of multiple: no top padding
64+
b.WriteString("<div class=\"post\" style=\"padding-top: 0;\">\n")
65+
} else if isLast {
66+
// Last of multiple: no bottom border
67+
b.WriteString("<div class=\"post\" style=\"border-bottom: none; padding-bottom: 0;\">\n")
68+
} else {
69+
b.WriteString("<div class=\"post\">\n")
70+
}
5671
b.WriteString("<div class=\"meta\">\n")
5772
//nolint:gocritic // %q would add extra quotes in HTML context
5873
b.WriteString(fmt.Sprintf("<a href=\"%s\" class=\"post-number\">#%s</a>\n", escapeHTML(post.URL), escapeHTML(post.ID)))

0 commit comments

Comments
 (0)