tinymail

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Go Reference Go Report Card

tinymail

tinymail is a small package to easily send simple emails in go.

Download

go get github.com/XotoX1337/tinymail

Features

  • SMTP Authentification
  • Email with text body
  • Email from Template as String or File
  • Attachments

Examples

Text Email
import "github.com/XotoX1337/tinymail"

mailer := tinymail.New(user, password, host)
msg := tinymail.FromText("this is a example")
msg.SetFrom("test@tinymail.test")
msg.SetTo("test.to@tinymail.test")
msg.SetSubject("TestWriteMessage")
err := mailer.SetMessage(msg).Send()
if err != nil {
    fmt.Println(err)
}
# send success
Email from Template
import "github.com/XotoX1337/tinymail"

mailer := tinymail.New(user, password, host)
msg := tinymail.FromTemplateFile(path/to/template/file)
msg.SetFrom("test@tinymail.test")
msg.SetTo("test.to@tinymail.test")
msg.SetSubject("TestWriteMessage")
err := mailer.SetMessage(msg).Send()
if err != nil {
    fmt.Println(err)
}
# send success
Email with Attachments
import "github.com/XotoX1337/tinymail"

mailer := tinymail.New(user, password, host)
msg := tinymail.FromText("attachment example")
msg.SetFrom("test@tinymail.test")
msg.SetTo("test.to@tinymail.test")
msg.SetSubject("TestWriteMessage")
msg.Attach(path/to/file, path/to/second/file, ...)
err := mailer.SetMessage(msg).Send()
if err != nil {
    fmt.Println(err)
}
# send success

Documentation

Overview

Package tinymail provides a simple and easy to use interface to send smtp emails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTemplateFile

func FromTemplateFile(data any, filenames ...string) (*message, error)

func FromTemplateString

func FromTemplateString(data any, tpl string) (*message, error)

func FromText

func FromText(text string) *message

func New

func New(user, password, host string) *mailer

Types

type Mailer

type Mailer interface {
	Send() error
	SetBoundary(boundary string)
	Boundary() string
}

type Message

type Message interface {
	SetFrom(from string)
	From() string
	SetTo(to ...string)
	To() []string
	SetCC(cc ...string)
	CC() []string
	SetBCC(bcc ...string)
	BCC() []string
	SetSubject(s string)
	Subject() string
	Attach(files ...string) error
	Attachments() map[string][]byte
	Body() string
	SetUrgentPriority()
	SetNonUrgentPriority()
	SetNormalPriority()
	Priority() string
}

Jump to

Keyboard shortcuts

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