Skip to content

spacetab-io/mails-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6bd7c7e · Jun 23, 2022

History

3 Commits
Jun 23, 2022
Jun 15, 2022
Jun 15, 2022
Jun 15, 2022
Jun 1, 2022
Jun 15, 2022
Jun 15, 2022
Jun 23, 2022
Jun 23, 2022
Jun 15, 2022
Jun 23, 2022
Jun 15, 2022

Repository files navigation

mails-go

Golang library for email sending.

Providers

List of available providers:

Usage

package main

import (
	"context"
	"time"

	"github.com/spacetab-io/configuration-structs-go/v2/configuration/mimetype"
	"github.com/spacetab-io/configuration-structs-go/v2/mailing"
	"github.com/spacetab-io/mails-go/contracts"
	"github.com/spacetab-io/mails-go/providers"
)

func main() {
	// 1. Get Provider config (with should implement mailing.MailProviderConfigInterface
	// For Example, Sendgrid Config
	sendgridCfg := mailing.SendgridConfig{
		Enabled:     true,
		Key:         "APIKey",
		SendTimeout: 5 * time.Second,
	}

	// 2. Initiate provider
	// Sendgrid provider
	sendgrid, err := providers.NewSendgrid(sendgridCfg)
	if err != nil {
		panic(err)
	}

	// 3. Prepare Message with should implement contracts.MessageInterface
	msg := contracts.Message{
		To: mailing.MailAddressList{
			{Email: "toOne@spacetab.io", Name: "To One"},
			{Email: "totwo@spacetab.io", Name: "To Two"},
		},
		MimeType: mime.TextPlain,
		Subject:  "Test email",
		Content:  []byte("test email content"),
	}

	// 4. Send message
	if err := sendgrid.Send(context.Background(), msg); err != nil {
		panic(err)
	}
}

About

Email sending library

Resources

License

Stars

Watchers

Forks

Packages

No packages published