email

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 8 Imported by: 0

README

Email

Usage
package main

import (
	"context"

	"gitlab.com/metricsglobal/misc-go/email"
)

func main() {
	provider, err := email.NewProvider(context.Background(), email.Opts{
		Provider: email.SMTPProvider, // Use smtp config
		SmtpConfig: &email.SmtpConfig{
			Host:     "smtp.google.com",
			Port:     587,
			Username: "username",
			Password: "<password>",
		},
	})
	if err != nil {
		panic(err)
	}

	// Set the data
	data := email.Data{
		Sender:   "john_testington@mgi.com",
		Subject:  "Important email",
		BodyHTML: `<html><body><h1>Welcome to my site</h1></body></html>`,
		Body:     "Welcome to my site",
		Charset:  email.DefaultCharset,
		ToAddresses: []string{
			"jane_testington@mgi.com",
		},
		CCAddresses: nil,
	}

	_, err = provider.Send(context.Background(), data)
	if err != nil {
		panic(err)
    }
}

Documentation

Index

Constants

View Source
const (
	AWSSesProvider provider = "aws-ses"
	SMTPProvider   provider = "smtp"

	DefaultCharset = "UTF-8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Sender   string
	Subject  string
	BodyHTML string
	Body     string
	// Charset of the email, default UTF-8
	Charset     string
	ToAddresses []string
	CCAddresses []string
}

func (*Data) Prepare

func (d *Data) Prepare()

func (Data) Validate

func (d Data) Validate() error

type Descriptor

type Descriptor interface {
	Send(ctx context.Context, data Data) (Response, error)
}

func NewProvider

func NewProvider(ctx context.Context, o Opts) (Descriptor, error)

type Opts

type Opts struct {
	Provider   provider
	SmtpConfig *SmtpConfig
}

type Response

type Response struct {
	MessageID string
}

type SmtpConfig

type SmtpConfig struct {
	Host     string
	Port     int
	Username string
	Password string
}

Jump to

Keyboard shortcuts

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