Send outgoing emails asyncronously
This commit is contained in:
parent
b93b2bafa5
commit
f97f38d4a9
|
@ -2,6 +2,7 @@ package alpsbase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.sr.ht/~emersion/alps"
|
"git.sr.ht/~emersion/alps"
|
||||||
|
"git.sr.ht/~sircmpwn/dowork"
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
imapmove "github.com/emersion/go-imap-move"
|
imapmove "github.com/emersion/go-imap-move"
|
||||||
imapclient "github.com/emersion/go-imap/client"
|
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
|
// Send message, append it to the Sent mailbox, mark the original message as
|
||||||
// answered
|
// answered
|
||||||
func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error {
|
func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error {
|
||||||
err := ctx.Session.DoSMTP(func(c *smtp.Client) error {
|
task := work.NewTask(func(_ context.Context) error {
|
||||||
return sendMessage(c, msg)
|
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 err != nil {
|
||||||
if _, ok := err.(alps.AuthError); ok {
|
if _, ok := err.(alps.AuthError); ok {
|
||||||
return echo.NewHTTPError(http.StatusForbidden, err)
|
return echo.NewHTTPError(http.StatusForbidden, err)
|
||||||
|
|
Loading…
Reference in a new issue