emailutils

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 12 Imported by: 0

README

emailutils

PkgGoDev

A simple package to send emails using the some of the most popular email services. It also include a package for sending otp codes to the user's email.

Stores

Here are the predefined stores for storing your otp codes:

  • InMemory: A simple in-memory store for storing the otp codes.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProviderNotSupported = fmt.Errorf("DNS Provider not supported")
	ErrNoFrom               = fmt.Errorf("from not provided")
	ErrNoRecipients         = fmt.Errorf("no recipients provided")
	ErrNoSubject            = fmt.Errorf("no subject provided")
	ErrNoBody               = fmt.Errorf("no body provided")
)

Errors

Functions

func RandomNum

func RandomNum(nbOfNumbers int) string

RandomNum generates random numbers

func RandomNumInt

func RandomNumInt(nbOfNumbers int) int

RandomNumInt generates random numbers

Types

type Attachment

type Attachment struct {
	Name        string
	ContentType string
	Data        []byte
}

func NewAttachment

func NewAttachment(name, contentType string, data []byte) *Attachment

func (*Attachment) Validate

func (a *Attachment) Validate() error

type Email

type Email struct {
	Subject     string
	From        *Person
	To          []*Person
	Cc          []*Person
	Bcc         []*Person
	Body        string
	Attachments []*Attachment
}

Define Email struct

func (*Email) Validate

func (e *Email) Validate() error

type Person

type Person struct {
	Name  string
	Email string
}

func NewPerson

func NewPerson(name, email string) *Person

func (*Person) String

func (p *Person) String() string

func (*Person) Validate

func (p *Person) Validate() error

type Provider

type Provider interface {
	Send(e *Email) error
	SupportAttachments() bool
}

Define the Provider interface

func GetProvider

func GetProvider(entity ProviderEntity, config ProviderConfig) (Provider, error)

GetProvider returns an email provider

type ProviderConfig

type ProviderConfig map[string]interface{}

func BuildMailgunConfig

func BuildMailgunConfig(domain, apiKey string) ProviderConfig

func BuildSMTPConfig

func BuildSMTPConfig(server string, port int, user, pass string, skipTls bool) ProviderConfig

func BuildSendgridConfig

func BuildSendgridConfig(apiKey string) ProviderConfig

type ProviderEntity

type ProviderEntity string
const (
	SMTPProvider ProviderEntity = "SMTP"
	// TODO: implement breo provider. // BrevoProvider    ProviderEntity = "BREVO"
	MailgunProvider  ProviderEntity = "MAILGUN"
	SendgridProvider ProviderEntity = "SENDGRID"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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