mail

package module
v0.0.0-...-11fe388 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 14 Imported by: 0

README

Mail Go

This package is created for supporting my work, I would be glad if the package can help you too.

Installation

go get github.com/oinpentuls/mail-go

Usage

Config the smtp server

options := mail.MailOptions{
    Host:     "host",
    Port:     "port",
    Username: "username",
    Password: "password",
}

construct new mail

mail := mail.New(options)
mail.SetFrom("hello@hello.com")
mail.SetTo([]string{"hallo@hallo.com"})
mail.SetSubject("Hello")

mail.SetBodyPlainText([]byte("Hello World"))

mail.SetBodyHTML([]byte("<h1>Hello World</h1>"))

err := mail.SetAttachment(filepath.Join("my_file.pdf"))
if err != nil {
    log.Fatal(err)
}

err = mail.Send()
if err != nil {
    log.Fatal(err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyAttachment = errors.New("attachment is empty")
View Source
var ErrEmptyBody = errors.New("body is empty")
View Source
var ErrEmptyFrom = errors.New("from is empty")
View Source
var ErrEmptyHost = errors.New("host is empty")
View Source
var ErrEmptyPassword = errors.New("password is empty")
View Source
var ErrEmptyPort = errors.New("port is empty")
View Source
var ErrEmptySubject = errors.New("subject is empty")
View Source
var ErrEmptyTo = errors.New("to is empty")
View Source
var ErrEmptyUsername = errors.New("username is empty")
View Source
var ErrFileNotFound = errors.New("file not found")

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Name        string
	Data        []byte
	ContentType string
}

type Message

type Message struct {
	Options Options
	// contains filtered or unexported fields
}

func New

func New(opt Options) *Message

New is used to create new instance of Message

func (*Message) Send

func (m *Message) Send() (err error)

func (*Message) SetAttachment

func (m *Message) SetAttachment(filename string) error

SetAttachment set attachment to email message param name is either path to file or url

func (*Message) SetBcc

func (m *Message) SetBcc(bcc []string)

func (*Message) SetBodyHTML

func (m *Message) SetBodyHTML(content []byte)

func (*Message) SetBodyPlainText

func (m *Message) SetBodyPlainText(content []byte)

func (*Message) SetCc

func (m *Message) SetCc(cc []string)

func (*Message) SetFrom

func (m *Message) SetFrom(from string)

func (*Message) SetSubject

func (m *Message) SetSubject(subject string)

func (*Message) SetTo

func (m *Message) SetTo(to []string)

type Options

type Options struct {
	Host     string
	Port     string
	Username string
	Password string
}

Jump to

Keyboard shortcuts

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