Giter VIP home page Giter VIP logo

aws-ses-go's Introduction

aws-ses-go

AWS SES with Golang package. Parses HTML templates with dynamic variables and with attachment files.

Usage example:

package main

import (
	"log"
	"os"

	"github.com/evzpav/aws-ses-go/email"
	"github.com/joho/godotenv"
)

var senderEmail string
var receiverEmail string
var awsRegion string
var awsAccessKeyId string
var awsSecretAccessKey string

func init() {
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}
	senderEmail = os.Getenv("SENDER_EMAIL")
	receiverEmail = os.Getenv("RECEIVER_EMAIL")
	awsRegion = os.Getenv("AWS_REGION")
	awsAccessKeyId = os.Getenv("AWS_ACCESS_KEY_ID")
	awsSecretAccessKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
}

func main() {

	vars := map[string]string{ //variables that will go to HTML template
		"name":         "evzpav",
		"info":         "123456",
		"supportEmail": senderEmail,
	}

	s := email.NewClient(awsRegion, awsAccessKeyId, awsSecretAccessKey)

	var baseLayoutVars = map[string]string{
		"supportEmail": senderEmail,
	}

	for k, v := range baseLayoutVars {
		vars[k] = v
	}

	//email based on HTML template
	var emailData = email.EmailData{
		From:           senderEmail,
		To:             []string{receiverEmail},
		ReplyTo:        []string{"[email protected]"},
		Subject:        "My email subject",
		TemplateName:   "examples/layout-and-attachment/html-templates/registration.html",
		TemplateVars:   vars,
		BaseLayoutPath: "examples/layout-and-attachment/html-templates/base_layout.html",
	}
	err := s.Send(emailData)

	if err != nil {
		log.Println(err)
	}

	//email based on HTML template with attachment
	var emailWithAttachment = email.EmailData{
		From:         senderEmail,
		To:           []string{receiverEmail},
		ReplyTo:      []string{"[email protected]"},
		Subject:      "My email subject",
		TemplateName: "email_template.html",
		TemplateVars: vars,
		AttachFiles: []string{"examples/layout-and-attachment/attachment-example/attachment.pdf",
			"examples/layout-and-attachment/attachment-example/attachment.txt"},
	}
	err = s.SendRaw(emailWithAttachment)

	if err != nil {
		log.Println(err)
	}
}

To run example:

cp .env_example .env
# Fill credentials and emails on .env file

go build

./aws-ses-go

aws-ses-go's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.