mail_sender

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 4 Imported by: 0

README

Mail Sender

This library is for sending emails from your mail

Installation

mail_sender can be installed like any other Go library through go get:

$ go get github.com/EfimReutov/mail_sender

Or, if you are already using Go Modules, you may specify a version number as well:

$ go get github.com/EfimReutov/mail_sender@latest

Getting Started

package main

import "github.com/EfimReutov/mail_sender"

func main() {
	sender := mail_sender.NewSender(
		mail_sender.Configuration{
			SMTPServer:   "smtp.gmail.com",
			SMTPPort:     587,
			MailUser:     "from@example.com",
			MailPassword: "examplePassword",
		},
	)
	dest := []string{
		"to@example.com",
	}

	data := struct {
		ExampleVariable string
	}{
		ExampleVariable: "example",
	}
	err := sender.WriteHTMLEmail(dest, "your subject", "templates/example.html", data)
	if err != nil {
		panic(err)
	}
	err = sender.WritePlainEmail(dest, "your subject", "text message")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	SMTPServer   string
	SMTPPort     int
	MailUser     string
	MailPassword string
}

type Message

type Message struct {
	ContentType string
	Recipients  []string
	Subject     string
	Body        []byte
}

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

func NewSender

func NewSender(cfg Configuration) *Sender

NewSender configures SMTP sender.

func (*Sender) WriteHTMLEmail

func (sender *Sender) WriteHTMLEmail(dest []string, subject, tmplName string, data interface{}) error

WriteHTMLEmail sends an HTML email based on your HTML template.

func (*Sender) WritePlainEmail

func (sender *Sender) WritePlainEmail(dest []string, subject, message string) error

WritePlainEmail sends a plain text email.

Jump to

Keyboard shortcuts

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