How to use resend.com api for sending emails? #2966
-
Resend allows to send email using their api. What would be the way to send email in this manner in pocketbase?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In order to use the builtin PocketBase email client (see "Sending custom emails") you need a provider that supports SMTP. Looking at Resend API documentation there is no mention for SMTP so I'm not sure if it is supported. In general you can initialize their SDK client as shown in your example. To intercept the system emails action (eg. for password reset) you can attach to the specific package main
import (
"log"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/hook"
)
func main() {
app := pocketbase.New()
app.OnMailerBeforeRecordResetPasswordSend().Add(func(e *core.MailerRecordEvent) error {
log.Println(e.Message.Subject)
log.Println(e.Message.From)
log.Println(e.Message.To)
log.Println(e.Message.HTML)
// use the above fields to send the email with the custom Resend SDK client...
return hook.StopPropagation
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
} In case Resend is not your final choice, here are some mail providers that have free tier and support SMTP:
Mailtrap also recently added, in addition to Email testing, support for Email sending with pretty generous free plan (1k mails/month without credit card) but I haven't personally tested them yet. |
Beta Was this translation helpful? Give feedback.
In order to use the builtin PocketBase email client (see "Sending custom emails") you need a provider that supports SMTP.
Looking at Resend API documentation there is no mention for SMTP so I'm not sure if it is supported.
In general you can initialize their SDK client as shown in your example. To intercept the system emails action (eg. for password reset) you can attach to the specific
OnMailer*
hook and returnhook.StopPropagation
. Something like: