ses

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 14 Imported by: 0

README

GSES - AWS SES Client From Go

A package to send emails using AWS SES, facilitating its abstraction using the SES GO SDK. In order for your email to be sent successfully using the aws sdk you need to have an email validated by SES (Verify This Email Address), console access can be done by clicking here https://console.aws.amazon.com/ses, it will Also need your Identity ARN.

Installation v2

go install github.com/jeffotoni/gses

Quickstart v2

package main

import (
	"context"
	"log"
	"os"
	"github.com/jeffotoni/gses/v2"
)

var (
	AWS_REGION            = os.Getenv("AWS_REGION")
	AWS_ACCESS_KEY_ID     = os.Getenv("AWS_ACCESS_KEY_ID")
	AWS_SECRET_ACCESS_KEY = os.Getenv("AWS_SECRET_ACCESS_KEY")
	
	AWS_FROM = os.Getenv("AWS_FROM")
	AWS_TO1  = os.Getenv("AWS_TO")
)

func main() {
	c := ses.NewClient(
		AWS_REGION,
		AWS_ACCESS_KEY_ID,
		AWS_SECRET_ACCESS_KEY,
	)

	req := models.DataEmail{
		ToAddresses:  []string{AWS_TO},
		From:         AWS_FROM,
		FromMsg:      "message",
		Title:        "Your Title here",
		MsgHTML:      "<h1>Your body message here using HTML</h1>",
	}

	if err := c.Send(context.Background(), req); err != nil {
		log.Fatal(err)
	}
}

Data Email and Attachment

When you send an email, it can have the following data:

type DataEmail struct {
	// Required at least 1
	ToAddresses  []string

	// Required
	From         string   
	
	// Required
	FromMsg      string   
	
	// Required
	Title        string   
	
	// Required
	MsgHTML      string   
	
	Charset      string

	BccAddresses []string

	CcAddresses  []string

	Attachments  []Attachment
}

type Attachment struct {
	Data []byte
	Name string
}

Attachments and copies


package main

import (
	"context"
	"log"
	"os"

	"github.com/jeffotoni/gses/v2"
)

var (
	AWS_REGION            = os.Getenv("AWS_REGION")
	AWS_ACCESS_KEY_ID     = os.Getenv("AWS_ACCESS_KEY_ID")
	AWS_SECRET_ACCESS_KEY = os.Getenv("AWS_SECRET_ACCESS_KEY")

	AWS_FROM = os.Getenv("AWS_FROM")
	AWS_TO1  = os.Getenv("AWS_TO1")
	AWS_TO2  = os.Getenv("AWS_TO2")
	AWS_MSG  = ""
)

func main() {
	c := ses.NewClient(
		AWS_REGION,
		AWS_ACCESS_KEY_ID,
		AWS_SECRET_ACCESS_KEY,
	)

	fname1 := "file1.pdf"
	data1, err := os.ReadFile(fname1)
	if err != nil {
		log.Fatal(err)
	}

	fname2 := "file2.pdf"
	data2, err := os.ReadFile(fname2)
	if err != nil {
		log.Fatal(err)
	}

	req := models.DataEmail{
		ToAddresses:  []string{AWS_TO1},
		From:         AWS_FROM,
		FromMsg:      "message",
		Title:        "Your Title here",
		MsgHTML:      "<h1>Your body message here using HTML and Attachments</h1>",
		BccAddresses: []string{AWS_TO1, AWS_TO2},
		CcAddresses:  []string{AWS_TO1},
		Attachments: []models.Attachment{
			{Data: data1, Name: fname1},
			{Data: data2, Name: fname2},
		},
	}

	if err := c.Send(context.Background(), req); err != nil {
		log.Fatal(err)
	}
}

Installation v0.0.5

This was the first version of sending email using SES AWS, and we will keep it working 100% just attachments will not work.

go install github.com/jeffotoni/gses@v0.0.5

Quickstart v0.0.5

Don't forget to add the environment variables

$ export AWS_REGION=""
$ export AWS_SECRET_ACCESS_KEY=""
$ export AWS_ACCESS_KEY_ID="" 
$ export AWS_IDENTITY=""
package main

import (
	"fmt"

	ses "github.com/jeffotoni/gses"
)

func main() {
	MsgHTML := `<h1>Test send Email</h1>`
	To := "your-email-here@email.com"
	From := "noreply@yourserver.com"
	FromMsg := "Message in email"
	Titule := "Your Titule Here"

	ok, err := ses.SendEmail(To, From, FromMsg, Titule, MsgHTML)
	fmt.Println(ok)
	fmt.Println(err)
}

Documentation

Overview

@autor: @jeffotoni

Index

Constants

This section is empty.

Variables

View Source
var (
	AWS_REGION            = os.Getenv("AWS_REGION")
	AWS_IDENTITY          = os.Getenv("AWS_IDENTITY")
	AWS_ACCESS_KEY_ID     = os.Getenv("AWS_ACCESS_KEY_ID")
	AWS_SECRET_ACCESS_KEY = os.Getenv("AWS_SECRET_ACCESS_KEY")
)

Functions

func AwsSesSetProfile

func AwsSesSetProfile(

	Region string,

	IdentityArn string,

	From string,

	Info string) *profile

func SendEmail

func SendEmail(To, From, FromMsg, Titulo, MsgHTML string) (err error)

SendEmail ..

func SendEmailSes

func SendEmailSes(To, From, FromMsg, Titulo, MsgHTML string) bool

SendEmailSes ..

Types

type Config added in v0.0.3

type Config struct {
	AWS_REGION            string `json:"AWS_REGION,omitempty"`
	AWS_IDENTITY          string `json:"AWS_IDENTITY,omitempty"`
	AWS_ACCESS_KEY_ID     string `json:"AWS_ACCESS_KEY_ID,omitempty"`
	AWS_SECRET_ACCESS_KEY string `json:"AWS_SECRET_ACCESS_KEY,omitempty"`
}

func New added in v0.0.3

func New(AWS_REGION, AWS_IDENTITY, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY string) *Config

func (*Config) SendEmailNew added in v0.0.3

func (c *Config) SendEmailNew(To, From, FromMsg, Titulo, MsgHTML string) (err error)

func (*Config) SendEmailSesNew added in v0.0.4

func (config *Config) SendEmailSesNew(To, From, FromMsg, Titulo, MsgHTML string) bool

SendEmailSes ..

type SesEmail

type SesEmail struct {
	Profiles map[string]*profile
	// contains filtered or unexported fields
}

SesEmail email struct We will assemble our data map with this structure

func (*SesEmail) SetSetupProfile

func (this *SesEmail) SetSetupProfile(name string, from string, replyTo []string, returnPath string, returnPathArn string, sourceArn string, region string) bool

Setup a profile to use with Send With this function, we were able to make the subtitle work correctly

Directories

Path Synopsis
snipets
@autor: @jeffotoni
@autor: @jeffotoni

Jump to

Keyboard shortcuts

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