Categorygithub.com/AccelByte/justice-go-common-email
repositorypackage
1.0.1
Repository: https://github.com/accelbyte/justice-go-common-email.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

justice-go-common-email

Go SDK for email sender functionality in AccelByte services.

Usage

Install

go get -u github.com/AccelByte/justice-go-common-email

Importing

"github.com/AccelByte/justice-go-common-email"

To create a new email sender client, use this function:

// If using static configuration
emailSender, errEmailSender := emailsender.NewEmailSender(emailsender.StaticSource)

// If using config service configuration
emailSender, errEmailSender := emailsender.NewEmailSender(emailsender.ConfigServiceSource)

Example initialize email sender client by environment variable:

var emailConfigSource emailsender.EmailConfigSource
if str := os.Getenv("APP_EMAIL_CONFIG_SOURCE"); str != "" { // using environment variable to decide the source config
	if str == string(emailsender.StaticSource) {
		emailConfigSource = emailsender.StaticSource
	} else if str == string(emailsender.ConfigServiceSource) {
		emailConfigSource = emailsender.ConfigServiceSource
	}
}
if emailConfigSource == nil {
	return errors.New("Source config is not valid")
}
emailSender, errEmailSender := emailsender.NewEmailSender(emailConfigSource)
if errEmailSender != nil {
	return errEmailSender
}

Supported Email Sender Configuration

Static Configuration

Read email sender configuration from environment variables.

Example initialization:

emailSender, errEmailSender := emailsender.NewEmailSender(emailsender.StaticSource)

Environment Variables

Environment VariableDescription
APP_EMAIL_SENDER_NAMEEmail sender platform. options: sendgrid, mandrill.
FROM_EMAIL_ADDRESSFrom email address, required.
FROM_EMAIL_NAMEFrom email name.
If using sendgrid platform:
Environment VariableDescription
SENDGRID_API_KEYSendgrid API Key, required.
SENDGRID_EMAIL_CATEGORIESSendgrid email categories.
If using mandrill platform:

There are 2 mode available when using mandrill platform: API and SMTP. You could decide which mode you want to activate by configuring the environment variables below, then it will automatically use the configured one:

Environment VariableDescriptionMode
MANDRILL_API_URLMandrill API URL (default: https://mandrillapp.com).API
MANDRILL_API_KEYMandrill API Key.API
MANDRILL_SMTP_HOSTMandrill SMTP Host (default: smtp.mandrillapp.com).SMTP
MANDRILL_SMTP_PORTMandrill SMTP Port (default: 587).SMTP
MANDRILL_USERNAMEMandrill username.SMTP
MANDRILL_PASSWORDMandrill password.SMTP

Config Service Configuration

Read email sender configuration from AccelByte Config Service.

Example initialization:

emailSender, errEmailSender := emailsender.NewEmailSender(emailsender.ConfigServiceSource)

Environment Variables

Environment VariableDescription
APP_CONFIG_SERVICE_REMOTE_HOSTConfig Service host to fetch the email sender configuration (default: http://justice-config-service/config)
APP_CONFIG_SERVICE_CACHE_EXPIREConfig Service cache expire in second (default: 60)
APP_EMAIL_SENDER_CACHE_EXPIREEmail sender platform cache expire in second (default: 60)

License

Copyright © 2023, AccelByte Inc. Released under the Apache License, Version 2.0