Documentation ¶
Index ¶
- Constants
- Variables
- func AttachJSON(message *mail.SGMailV3, data []byte, filename string) (err error)
- func DailyUsersEmail(data DailyUsersData) (message *mail.SGMailV3, err error)
- func InviteEmail(data InviteData) (message *mail.SGMailV3, err error)
- func LoadAttachment(message *mail.SGMailV3, attachmentPath string) (err error)
- func Render(name string, data interface{}) (text, html string, err error)
- func VerifyEmail(data VerifyEmailData) (message *mail.SGMailV3, err error)
- func WelcomeEmail(data WelcomeData) (message *mail.SGMailV3, err error)
- type Config
- type DailyUsersData
- type EmailData
- type EmailManager
- type InviteData
- type SendGridClient
- type VerifyEmailData
- type WelcomeData
Examples ¶
Constants ¶
const ( UnknownDate = "unknown date" DateFormat = "Monday, January 2, 2006" )
const ( WelcomeRE = "Welcome to Ensign!" VerifyEmailRE = "Please verify your email address to login to Ensign" InviteRE = "Join Your Teammate %s on Ensign!" DailyUsersRE = "Daily PLG Report for %s: %s" )
Email subject lines
Variables ¶
Functions ¶
func AttachJSON ¶ added in v0.4.0
AttachJSON by marshaling the specified data into human-readable data and encode and attach it to the email as a file.
func DailyUsersEmail ¶ added in v0.5.2
func DailyUsersEmail(data DailyUsersData) (message *mail.SGMailV3, err error)
DailyUsersEmail creates an email to send to admins that reports the PLG status
func InviteEmail ¶ added in v0.5.2
func InviteEmail(data InviteData) (message *mail.SGMailV3, err error)
InviteEmail creates an email to invite a user to join an organization
func LoadAttachment ¶ added in v0.4.0
LoadAttachment onto email from a file on disk.
func Render ¶ added in v0.4.0
Render returns the text and html executed templates for the specified name and data. Ensure that the extension is not supplied to the render method.
func VerifyEmail ¶ added in v0.5.0
func VerifyEmail(data VerifyEmailData) (message *mail.SGMailV3, err error)
VerifyEmail creates an email to verify a user's email address
func WelcomeEmail ¶ added in v0.4.0
func WelcomeEmail(data WelcomeData) (message *mail.SGMailV3, err error)
WelcomeEmail creates a welcome email for a new user
Types ¶
type Config ¶
type Config struct { APIKey string `split_words:"true" required:"false"` FromEmail string `split_words:"true" default:"ensign@rotational.io"` AdminEmail string `split_words:"true" default:"admins@rotational.io"` EnsignListID string `split_words:"true" required:"false"` Testing bool `split_words:"true" default:"false"` Archive string `split_words:"true"` }
Configures SendGrid for sending emails and managing marketing contacts.
type DailyUsersData ¶ added in v0.5.2
type DailyUsersData struct { EmailData Date time.Time `json:"date"` InactiveDate time.Time `json:"inactive_date"` Domain string `json:"domain"` EnsignDashboardLink string `json:"dashboard_url"` NewUsers int `json:"new_users"` DailyUsers int `json:"daily_users"` ActiveUsers int `json:"active_users"` InactiveUsers int `json:"inactive_users"` APIKeys int `json:"api_keys"` ActiveKeys int `json:"active_keys"` InactiveKeys int `json:"inactive_keys"` RevokedKeys int `json:"revoked_keys"` Organizations int `json:"organizations"` NewOrganizations int `json:"new_organizations"` Projects int `json:"projects"` NewProjects int `json:"new_projects"` }
DailyUsersData is used to complete the daily users email template
func (DailyUsersData) FormattedDate ¶ added in v0.5.2
func (d DailyUsersData) FormattedDate() string
func (DailyUsersData) FormattedInactiveDate ¶ added in v0.5.2
func (d DailyUsersData) FormattedInactiveDate() string
func (DailyUsersData) TabTable ¶ added in v0.5.2
func (d DailyUsersData) TabTable() string
Example ¶
package main import ( "fmt" "github.com/rotationalio/ensign/pkg/utils/emails" ) func main() { dailyUsersData := emails.DailyUsersData{ Domain: "ensign.local", NewUsers: 2, DailyUsers: 8, ActiveUsers: 102, InactiveUsers: 3, APIKeys: 58, ActiveKeys: 52, InactiveKeys: 6, RevokedKeys: 12, Organizations: 87, NewOrganizations: 1, Projects: 87, NewProjects: 1, } fmt.Println(dailyUsersData.TabTable()) }
Output: New Users: 2 Daily Users: 8 Active Users: 102 Inactive Users: 3 API Keys: 58 Revoked API Keys: 12 Active API Keys: 52 Inactive API Keys: 6 New Organizations: 1 Organizations: 87 New Projects: 1 Projects: 87
type EmailData ¶ added in v0.4.0
type EmailData struct { Subject string `json:"-"` Sender sendgrid.Contact `json:"-"` Recipient sendgrid.Contact `json:"-"` }
EmailData includes data fields that are common to all the email builders such as the subject and sender/recipient information.
type EmailManager ¶
type EmailManager struct {
// contains filtered or unexported fields
}
EmailManager allows a server to send rich emails using the SendGrid service.
func New ¶
func New(conf Config) (m *EmailManager, err error)
New email manager with the specified configuration.
func (*EmailManager) AddContact ¶ added in v0.4.0
func (m *EmailManager) AddContact(contact *sg.Contact, listIDs ...string) (err error)
AddContact adds a contact to SendGrid, adding them to the Ensign marketing list if it is configured. This is an upsert operation so existing contacts will be updated. The caller can optionally specify additional lists that the contact should be added to. If no lists are configured or specified, then the contact is added or updated in SendGrid but is not added to any marketing lists.
type InviteData ¶ added in v0.5.2
type InviteData struct { EmailData Email string InviterName string OrgName string Role string InviteURL string }
InviteData is used to complete the invite email template
type SendGridClient ¶
SendGridClient is an interface that can be implemented by live email clients to send real emails or by mock clients for testing.
type VerifyEmailData ¶ added in v0.5.0
VerifyEmailData is used to complete the verify email template