diff --git a/app/notification.go b/app/notification.go index 4e4b79c52a..729e983b11 100644 --- a/app/notification.go +++ b/app/notification.go @@ -646,6 +646,11 @@ func max(a, b int64) int64 { } func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool { + // if user is a bot account, then we do not send email + if user.IsBot { + return false + } + userAllowsEmails := user.NotifyProps[model.EmailNotifyProp] != "false" // if CRT is ON for user and the post is a reply disregard the channelEmail setting diff --git a/app/notification_test.go b/app/notification_test.go index 6c8835d855..be5666c654 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -2488,6 +2488,19 @@ func TestUserAllowsEmail(t *testing.T) { assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder})) }) + t.Run("should return false in the case user is a bot", func(t *testing.T) { + user := th.CreateUser() + + th.App.ConvertUserToBot(user) + + channelMemberNotifcationProps := model.StringMap{ + model.EmailNotifyProp: model.ChannelNotifyDefault, + model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll, + } + + assert.False(t, th.App.userAllowsEmail(user, channelMemberNotifcationProps, &model.Post{Type: model.PostTypeAutoResponder})) + }) + } func TestInsertGroupMentions(t *testing.T) {