emailtemplates

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

README

Build status Go Report Card Go Reference Quality Gate Status

Email Templates

This repository contains some of the common emails which would be sent to users of the Openlane platform.

Example Usage

    // setup config using options
   	config, err := emailtemplates.New(
		emailtemplates.WithCompanyName("Avengers"),
		emailtemplates.WithCompanyAddress("1337 Main St. ·Metropolis, NY 10010"),
		emailtemplates.WithCorporation("avengers, Inc."),
		emailtemplates.WithSupportEmail("support@avengers.com"),
		emailtemplates.WithFromEmail("no-reply@mail.avengers.com"),
		emailtemplates.WithRootDomain("https://www.avengers.com"),
		emailtemplates.WithDocsDomain("https://docs.avengers.com"),
		emailtemplates.WithProductDomain("https://console.avengers.com"),
	)
    if err != nil {
        return err
    }

    // create email message
	email, err := config.NewWelcomeEmail(
		emailtemplates.Recipient{
			Email:     "ironman@example.com",
			FirstName: "Tony",
			LastName:  "Stark",
		}, "Avengers",
	)
    if err != nil {
        return err
    }

    // we recommend the use of the https://github.com/theopenlane/newman package to send the email
    // which supports several providers including Resend, Mailgun, etc.
    // for brevity, this won't show how to create the client and assumes it was created beforehand
    if err := newmanClient.SendEmailWithContext(ctx, email); err != nil {
        return err
    }

Variables

Required Variables For All Templates
Variable Example
.CompanyName Openlane
.CompanyAddress 1337 Main St. ·Metropolis, NY 10010
.Corporation theopenlane, Inc.
.SupportEmail support@theopenlane.io
.FromEmail no-reply@mail.theopenlane.io
.URLS.Root https://theopenlane.io
.URLS.Product https://console.theopenlane.io
.URLS.Docs https://docs.theopenlane.io
Additional Variables for Specific Templates
Template Name Variable Example Value
Email Verification .URLS.Verify https://console.theopenlane.io/verify
Subscriber Verification .URLS.VerifySubscriber https://theopenlane.io/verify
Password Reset .URLS.PasswordReset https://console.theopenlane.io/password-reset
Invite Acceptance .URLS.Invite https://console.theopenlane.io/invite
Optional Variables
Variable Example
.LogoURL http://api.example.com/assets/logo.png

Editing

These are the actual emails, language, format, that will be sent to users of Openlane platform so please exercise care with their updates. If you're uncertain, feel free to reach out to @matoszz for assistance.

Contributing

See the contributing guide for more information

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingTemplate is returned when an email template is missing from the template directory
	ErrMissingTemplate = errors.New("missing email template")
)

Functions

func Render

func Render(name string, data interface{}) (text, html string, err error)

Render returns the text and html executed templates for the specified name and data

Types

type Config

type Config struct {
	// CompanyName is the name of the company that is sending the email
	CompanyName string `koanf:"companyName" json:"companyName" default:""`
	// CompanyAddress is the address of the company that is sending the email, included in the footer
	CompanyAddress string `koanf:"companyAddress" json:"companyAddress" default:""`
	// Corporation is the official corporation name that is sending the email, included in the footer
	Corporation string `koanf:"corporation" json:"corporation" default:""`
	// FromEmail is the email address that the email is sent from
	FromEmail string `koanf:"fromEmail" json:"fromEmail" default:""`
	// SupportEmail is the email address that the recipient can contact for support
	SupportEmail string `koanf:"supportEmail" json:"supportEmail" default:""`
	// LogoURL is the URL to the company logo that is included in the email if provided
	LogoURL string `koanf:"logoURL" json:"logoURL" default:""`
	// URLS includes URLs that are used in the email templates
	URLS URLConfig `koanf:"urls" json:"urls"`
}

Config includes fields that are common to all the email builders that are configurable

func New

func New(options ...Option) (*Config, error)

New is a function that creates a new config for the email templates

func (Config) NewInviteAcceptedEmail

func (c Config) NewInviteAcceptedEmail(r Recipient, i InviteTemplateData) (*newman.EmailMessage, error)

NewInviteEmail returns a new email message based on the config values and the provided recipient and invite data

func (Config) NewInviteEmail

func (c Config) NewInviteEmail(r Recipient, i InviteTemplateData, token string) (*newman.EmailMessage, error)

NewInviteEmail returns a new email message based on the config values and the provided recipient and invite data

func (Config) NewPasswordResetRequestEmail

func (c Config) NewPasswordResetRequestEmail(r Recipient, token string) (*newman.EmailMessage, error)

NewPasswordResetRequestEmail returns a new email message based on the config values and the provided recipient and token

func (Config) NewPasswordResetSuccessEmail

func (c Config) NewPasswordResetSuccessEmail(r Recipient) (*newman.EmailMessage, error)

NewPasswordResetSuccessEmail returns a new email message based on the config values and the provided recipient

func (Config) NewSubscriberEmail

func (c Config) NewSubscriberEmail(r Recipient, organizationName, token string) (*newman.EmailMessage, error)

NewSubscriberEmail returns a new email message based on the config values and the provided recipient, organization name, and token

func (Config) NewVerifyEmail

func (c Config) NewVerifyEmail(r Recipient, token string) (*newman.EmailMessage, error)

NewVerifyEmail returns a new email message based on the config values and the provided recipient and token

func (Config) NewWelcomeEmail

func (c Config) NewWelcomeEmail(r Recipient, org string) (*newman.EmailMessage, error)

NewWelcomeEmail returns a new email message based on the config values and the provided recipient and organization name

type EmailData

type EmailData struct {
	Config
	// Subject is the subject line of the email
	Subject string `json:"subject"`
	// Recipient is the person who will receive the email
	Recipient Recipient `json:"recipient"`
}

EmailData includes data fields that are common to all the email builders

func (EmailData) Build

func (e EmailData) Build(text, html string) (*newman.EmailMessage, error)

Build valids and creates a new email from pre-rendered templates

func (EmailData) Validate

func (e EmailData) Validate() error

Validate that all required data is present to assemble a sendable email

type InviteData

type InviteData struct {
	EmailData

	// InviterName is the name of the person who is inviting the recipient
	InviterName string `json:"inviter_name"`
	// OrganizationName is the name of the organization that the user is being invited to
	OrganizationName string `json:"organization_name"`
	// Role is the role that the user is being invited to join the organization as
	Role string `json:"role"`
}

InviteData includes fields for the invite email

type InviteTemplateData

type InviteTemplateData struct {
	InviterName      string
	OrganizationName string
	Role             string
}

InviteTemplateData includes the data needed to render the invite email templates

type MissingRequiredFieldError

type MissingRequiredFieldError struct {
	// RequiredField that is missing
	RequiredField string
}

MissingRequiredFieldError is returned when a required field was not provided in a request

func (*MissingRequiredFieldError) Error

func (e *MissingRequiredFieldError) Error() string

Error returns the MissingRequiredFieldError in string format

type Option

type Option func(*Config)

Option is a function that sets a field on an EmailMessage

func WithCompanyAddress

func WithCompanyAddress(address string) Option

WithCompanyAddress sets company address for the footer of the email

func WithCompanyName

func WithCompanyName(name string) Option

WithCompanyName sets the company name for the email

func WithCorporation

func WithCorporation(corp string) Option

WithCorporation sets the corporation used in the footer of the email

func WithDocsDomain

func WithDocsDomain(domain string) Option

WithDocsDomain sets the docs domain for the email

func WithFromEmail

func WithFromEmail(email string) Option

WithFromEmail sets the from email for the email

func WithInviteURL

func WithInviteURL(url string) Option

WithInviteURL sets the invite URL for the email

func WithLogoURL

func WithLogoURL(url string) Option

WithLogoURL sets the logo URL for the email, this field is optional and omitted from the email if not provided

func WithProductDomain

func WithProductDomain(domain string) Option

WithProductDomain sets the product domain for the email

func WithResetURL

func WithResetURL(url string) Option

WithResetURL sets the reset URL for the email

func WithRootDomain

func WithRootDomain(domain string) Option

WithRootDomain sets the root domain for the email

func WithSupportEmail

func WithSupportEmail(email string) Option

WithSupportEmail sets the support email for the email

func WithVerifySubscriberURL

func WithVerifySubscriberURL(url string) Option

WithVerifySubscriberURL sets the verify subscriber URL for the email

func WithVerifyURL

func WithVerifyURL(url string) Option

WithVerifyURL sets the verify URL for the email

type Recipient

type Recipient struct {
	// Email is the email address of the recipient
	Email string `json:"email"`
	// FirstName is the first name of the recipient
	FirstName string `json:"first_name"`
	// LastName is the last name of the recipient
	LastName string `json:"last_name"`
}

Recipient includes fields for the recipient of the email

type ResetRequestData

type ResetRequestData struct {
	EmailData
}

ResetRequestData includes fields for the password reset request email

type ResetSuccessData

type ResetSuccessData struct {
	EmailData
}

ResetSuccessData includes fields for the password reset success email

type SubscriberEmailData

type SubscriberEmailData struct {
	EmailData

	// Organization is the name of the organization that the user is subscribing to
	OrganizationName string `json:"organization_name"`
}

SubscriberEmailData includes fields for the subscriber email

type URLConfig

type URLConfig struct {
	// Root is the root domain for the email
	Root string `koanf:"root" json:"root" default:""`
	// Product is the product domain for the email, usually the main UI where a user logs in
	Product string `koanf:"product" json:"product" default:""`
	// Docs is the docs domain for the email, where a user can find documentation
	Docs string `koanf:"docs" json:"docs" default:""`
	// Verify is the URL to verify an email address
	Verify string `koanf:"verify" json:"verify" default:""`
	// Invite is the URL to accept an invite to an organization
	Invite string `koanf:"invite" json:"invite" default:""`
	// PasswordReset is the URL to reset a password
	PasswordReset string `koanf:"reset" json:"reset" default:""`
	// VerifySubscriber is the URL to verify a subscriber for an organization
	VerifySubscriber string `koanf:"verifySubscriber" json:"verifySubscriber" default:""`
}

URLConfig includes urls that are used in the email templates

type VerifyEmailData

type VerifyEmailData struct {
	EmailData
}

VerifyEmailData includes fields for the verify email

type WelcomeData

type WelcomeData struct {
	EmailData

	// Organization is the name of the organization that the user is joining
	Organization string `json:"organization"`
}

WelcomeData includes fields for the welcome email

Jump to

Keyboard shortcuts

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