From f97f38d4a9550bb15d39cfc05a3011e969927d22 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 23 Oct 2020 14:15:07 -0400 Subject: Send outgoing emails asyncronously --- plugins/base/routes.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 3cad8da..7ba6253 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -2,6 +2,7 @@ package alpsbase import ( "bytes" + "context" "fmt" "io" "io/ioutil" @@ -12,6 +13,7 @@ import ( "strings" "git.sr.ht/~emersion/alps" + "git.sr.ht/~sircmpwn/dowork" "github.com/emersion/go-imap" imapmove "github.com/emersion/go-imap-move" imapclient "github.com/emersion/go-imap/client" @@ -408,9 +410,12 @@ type composeOptions struct { // Send message, append it to the Sent mailbox, mark the original message as // answered func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error { - err := ctx.Session.DoSMTP(func(c *smtp.Client) error { - return sendMessage(c, msg) - }) + task := work.NewTask(func(_ context.Context) error { + return ctx.Session.DoSMTP(func (c *smtp.Client) error { + return sendMessage(c, msg) + }) + }).Retries(5) + err := ctx.Server.Queue.Enqueue(task) if err != nil { if _, ok := err.(alps.AuthError); ok { return echo.NewHTTPError(http.StatusForbidden, err) -- cgit v1.2.3