Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

50 lines
1.4 KiB
Go

package tasks
import (
"context"
"errors"
"github.com/hanzoai/commerce/delay"
"github.com/hanzoai/commerce/log"
"github.com/hanzoai/commerce/thirdparty/mandrill"
"github.com/hanzoai/commerce/thirdparty/sendgrid"
"github.com/hanzoai/commerce/thirdparty/smtprelay"
"github.com/hanzoai/commerce/types/email"
"github.com/hanzoai/commerce/types/integration"
)
func getEmailSender(c context.Context, in integration.Integration) (email.Sender, error) {
switch in.Type {
case integration.MandrillType:
log.Info("Using Mandrill", c)
return mandrill.New(c, in.Mandrill), nil
case integration.SendGridType:
log.Info("Using SendGrid", c)
return sendgrid.New(c, in.SendGrid), nil
case integration.SMTPRelayType:
log.Info("Using SMTPRelay", c)
return smtprelay.New(c, in.SMTPRelay), nil
default:
log.Error("Invalid Email Provider", c)
return nil, errors.New("Invalid Email Provider")
}
}
// Send email with appropriate provider
var Send = delay.Func("email-send", func(c context.Context, in integration.Integration, message *email.Message) error {
log.Debug("Sending email to %s, %v", message.To[0], message, c)
provider, err := getEmailSender(c, in)
if err != nil {
return log.Error("Email provider integration not found: %v", err, c)
}
err = provider.Send(message)
if err != nil {
return log.Error("Email provider error: %v", err, c)
}
return nil
})