resend

package
v0.241.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigEnvPrefix is the prefix applied to environment variables for configuring Resend.
	ConfigEnvPrefix = "RESEND_"

	// TagUserID is a tag containing a user ID.
	TagUserID string = "user_id"
	// TagCategory is a tag containing a category.
	TagCategory string = "category"
	// TagCategoryPromotional is the promotional category.
	TagCategoryPromotional string = "promotional"
	// TagCategoryAccount is the account category.
	TagCategoryAccount string = "account"
	// TagCategorySupport is the support category.
	TagCategorySupport string = "support"
)

Variables

View Source
var ErrInvalidEmail = errors.New("email is invalid")

Functions

func DecodeEmail added in v0.87.0

func DecodeEmail(token string) (string, error)

DecodeEmail decrypts and returns the plain-text email encrypted by EncodeEmail.

func EncodeEmail added in v0.87.0

func EncodeEmail(email string) (string, error)

EncodeEmail encrypts an email using AES-GCM with a key derived from the passphrase + salt. The result is URL-safe base64 (no padding).

func ForwardAdminEmail added in v0.143.0

func ForwardAdminEmail(ctx context.Context, received *EmailRecieved) error

func IsValidReplyTo added in v0.143.0

func IsValidReplyTo(to []string) (bool, error)

func UpdateTemplate added in v0.86.0

func UpdateTemplate(ctx context.Context, alias string, options ...TemplateOption) error

UpdateTemplate will update the template with the given alias. If a template with the alias does not exist, it will be created.

func WithFrom added in v0.122.0

func WithFrom[T HasFrom](from any) func(T)

WithFrom option sets the from field for the email.

func WithRemoteAttachment added in v0.126.0

func WithRemoteAttachment[T HasAttachment](attachment *Attachment) func(T)

WithRemoteAttachment option defines a remote file attachment to add to the email.

func WithReplyTo added in v0.122.0

func WithReplyTo[T HasReplyTo](replyTo any) func(T)

WithReplyTo option sets the reply-to field for the email.

func WithSubject added in v0.122.0

func WithSubject[T HasSubject](subject string) func(T)

WithSubject option sets the subject field for the email.

func WithTo added in v0.126.0

func WithTo[T HasTo](to any) func(T)

WithTo option sets the to field for the email. Can be specified multiple times when sending an email to send to multiple recipients.

Types

type Address added in v0.122.0

type Address interface {
	string | *mail.Address
}

type Attachment added in v0.25.0

type Attachment struct {
	*resend.Attachment
}

func NewRemoteFileAttachment added in v0.126.0

func NewRemoteFileAttachment(path, name string) *Attachment

type BatchSendResponse added in v0.87.0

type BatchSendResponse []SendResponse

BatchSendResponse contains data related to a batch email request.

type Client added in v0.239.2

type Client struct {
	*resend.Client
	Config *Config
}

type Config

type Config struct {
	WebHookSecret string `koanf:"webhooksecret" validate:"required"`
	APIKey        string `koanf:"apikey"        validate:"required"`
	AdminEmail    string `koanf:"adminemail"    validate:"required,email"`
	ReplyToEmail  string `koanf:"replyto"       validate:"required,email"`
	Key           string `koanf:"key"           validate:"required"`
	Salt          string `koanf:"salt"          validate:"required"`
}

Config is the configuration values for the Resend service.

type Email added in v0.87.0

type Email struct {
	*resend.Email
	// contains filtered or unexported fields
}

Email is an email to be processed with the resend API.

func NewTemplatedEmail added in v0.87.0

func NewTemplatedEmail(templateID string, options ...EmailOption) (*Email, error)

NewTemplatedEmail creates a new email using the given template and with any options specified.

func (*Email) SetFrom added in v0.126.0

func (e *Email) SetFrom(from any)

func (*Email) SetRemoteAttachment added in v0.126.0

func (e *Email) SetRemoteAttachment(attachment *Attachment)

func (*Email) SetReplyTo added in v0.126.0

func (e *Email) SetReplyTo(replyTo any)

func (*Email) SetSubject added in v0.126.0

func (e *Email) SetSubject(subject string)

func (*Email) SetTo added in v0.126.0

func (e *Email) SetTo(to any)

func (*Email) Validate added in v0.222.0

func (e *Email) Validate() error

type EmailOption added in v0.61.0

type EmailOption func(*Email)

EmailOption is a functional option to apply to an email.

func WithExistingEmail added in v0.91.1

func WithExistingEmail(data *Email) EmailOption

func WithHTMLContent added in v0.91.1

func WithHTMLContent(html string) EmailOption

WithHTMLContent option sets the html content of the email. When using this option, it is advised to also use the WithTextContent option to set the text content of the email shown to clients that don't support html emails.

func WithTag added in v0.61.0

func WithTag(key string, value string) EmailOption

WithTag option applies the given tag to the email.

func WithTextContent added in v0.91.1

func WithTextContent(text string) EmailOption

WithTextContent option sets the text content of the email (shown in clients that don't support HTML emails).

func WithVariable added in v0.86.0

func WithVariable(key string, value any) EmailOption

WithVariable option assigns a value to the given template variable in the email template.

type EmailRecieved added in v0.25.0

type EmailRecieved struct {
	EmailId     string       `json:"email_id,omitempty"`
	CreatedAt   string       `json:"created_at,omitempty"`
	From        string       `json:"from,omitempty"`
	To          []string     `json:"to,omitempty"`
	Bcc         []string     `json:"bcc,omitempty"`
	Cc          []string     `json:"cc,omitempty"`
	MessageId   string       `json:"message_id,omitempty"`
	Subject     string       `json:"subject,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

type HasAttachment added in v0.126.0

type HasAttachment interface {
	*Email

	SetRemoteAttachment(attachment *Attachment)
}

type HasFrom added in v0.122.0

type HasFrom interface {
	*Template | *ReceivedEmail | *Email

	SetFrom(replyTo any)
}

type HasReplyTo added in v0.122.0

type HasReplyTo interface {
	*Template | *ReceivedEmail | *Email

	SetReplyTo(replyTo any)
}

type HasSubject added in v0.122.0

type HasSubject interface {
	*Template | *ReceivedEmail | *Email

	SetSubject(subject string)
}

type HasTo added in v0.126.0

type HasTo interface {
	*Email

	SetTo(to any)
}

type ItemService added in v0.239.2

type ItemService interface {
	AddItems(ctx context.Context, items models.Items) (map[string]models.Items, error)
}

type ReceivedEmail added in v0.25.0

type ReceivedEmail struct {
	*resend.ReceivedEmail
}

func GetFullEmail added in v0.143.0

func GetFullEmail(ctx context.Context, id string) (*ReceivedEmail, error)

func (*ReceivedEmail) ExtractAttachments added in v0.61.0

func (e *ReceivedEmail) ExtractAttachments(ctx context.Context) ([]*resend.Attachment, error)

ExtractAttachments will extract and return the attachments on the email, if any.

func (*ReceivedEmail) Forward added in v0.61.0

func (e *ReceivedEmail) Forward(ctx context.Context, to ...string) error

Forward will forward the recieved email to the given addresses.

func (*ReceivedEmail) GetBody added in v0.25.0

func (e *ReceivedEmail) GetBody() string

func (*ReceivedEmail) GetFrom added in v0.25.0

func (e *ReceivedEmail) GetFrom() *mail.Address

func (*ReceivedEmail) GetID added in v0.25.0

func (e *ReceivedEmail) GetID() string

func (*ReceivedEmail) GetSubject added in v0.25.0

func (e *ReceivedEmail) GetSubject() string

func (*ReceivedEmail) Timestamp added in v0.25.0

func (e *ReceivedEmail) Timestamp() time.Time

func (*ReceivedEmail) Validate added in v0.222.0

func (e *ReceivedEmail) Validate() error

Valid returns a non-nil error when the ReceivedEmail contains invalid fields.

type Receiver added in v0.240.0

type Receiver struct {
	// contains filtered or unexported fields
}

Receiver handles received emails.

func NewReceiver added in v0.240.0

func NewReceiver(
	subs SubscriptionsService, users UserService, items ItemService,
	newSub SubscriptionFactory,
) *Receiver

func (*Receiver) Process added in v0.240.0

func (p *Receiver) Process(ctx context.Context, details EmailRecieved) error

Process processes the received email. It forwards admin emails or handles adding articles/creating subscriptions for a user.

type SendResponse added in v0.87.0

type SendResponse struct {
	To    []string
	Error error
}

SendResponse contains details about an individual email sent status.

type Sender added in v0.240.0

type Sender struct {
	*Client
}

Sender handles sending emails.

func NewSender added in v0.240.0

func NewSender() (*Sender, error)

func (*Sender) BatchSend added in v0.240.0

func (s *Sender) BatchSend(ctx context.Context, emails ...*Email) (BatchSendResponse, error)

BatchSend sends the given emails in a batch request.

func (*Sender) Send added in v0.240.0

func (s *Sender) Send(ctx context.Context, options ...EmailOption) error

Send sends the given email.

type SubscriptionFactory added in v0.239.2

type SubscriptionFactory func(ctx context.Context, userID string, from *mail.Address) (*models.Subscription, error)

SubscriptionFactory wraps service.NewEmailSubscription.

type SubscriptionsService added in v0.239.2

type SubscriptionsService interface {
	GetAllSubscriptions(ctx context.Context) (models.Subscriptions, error)
	AddSubscriptions(ctx context.Context, subscriptions ...*models.Subscription) error
}

type Template added in v0.122.0

type Template struct {
	*resend.UpdateTemplateRequest
	// contains filtered or unexported fields
}

func (*Template) SetFrom added in v0.122.0

func (t *Template) SetFrom(from any)

func (*Template) SetReplyTo added in v0.122.0

func (t *Template) SetReplyTo(replyTo any)

func (*Template) SetSubject added in v0.122.0

func (t *Template) SetSubject(subject string)

type TemplateOption added in v0.86.0

type TemplateOption func(*Template)

TemplateOption is a functional option applied to a template.

func WithTemplateHTML added in v0.86.0

func WithTemplateHTML(data []byte) TemplateOption

WithTemplateHTML option sets the HTML format of the template.

func WithTemplateName added in v0.86.0

func WithTemplateName(name string) TemplateOption

WithTemplateName option sets the name of the template.

func WithTemplateText added in v0.86.0

func WithTemplateText(data []byte) TemplateOption

WithTemplateText option sets the text format of the template.

func WithTemplateVariable added in v0.48.0

func WithTemplateVariable(key, dataType string, fallback any) TemplateOption

WithTemplateVariable option sets a variable for use within the template.

type UserService added in v0.239.2

type UserService interface {
	GetUserBySubscriptionEmail(ctx context.Context, emails ...string) (*models.User, error)
}

type Verifier added in v0.239.2

type Verifier struct {
	*Client
}

Verifier handles verification of incoming webhook data.

func NewVerifier added in v0.239.2

func NewVerifier() (*Verifier, error)

func (*Verifier) Verify added in v0.239.2

func (v *Verifier) Verify(req *http.Request, body []byte) error

Verify performs verification of the webhook data received in the given request.

type WebhookEmailReceieved added in v0.25.0

type WebhookEmailReceieved struct {
	Type      string        `json:"type,omitempty"`
	CreatedAt string        `json:"created_at,omitempty"`
	Data      EmailRecieved `json:"data,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL