gosmtp

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 17 Imported by: 1

README

gosmtp

Usage example
func main() {
    client := gosmtp.NewSender(
        "admin1",
        "sosecretpassword",
        "admin1@example.com",
        "smtp.example.com:465")
    var recipients = [][]string{
        {"user1@example.com", "user2@example.com"},
        {"user3@example.com", "user4@example.com"},
    }
    var files = []string{
        "file1.jpeg",
        "file2.mp3",
    }
    for _, recs := range recipients {
        var msg = gosmtp.NewMessage().
            SetTO(recs...).
            SetSubject("hello world").
            SetText("something text").
            AddAttaches(files...)
        if err := client.SendMessage(msg); err != nil {
            log.Fatalln(err)
        }
    }
}

Works with mail services:

  • mail.yandex.ru
  • e.mail.ru
  • gmail.com

TODO:

  • STARTTLS may be not worked. On outlook (smtp.office365.com:587) not work

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename string
	MIME     string
	Data     []byte
}

Attachment - simple file attachment structure

type Message

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

Message - тело сообщения

func NewMessage

func NewMessage() *Message

NewMessage - create new message

func (*Message) AddAttaches

func (m *Message) AddAttaches(attchs ...string) *Message

AddAttaches - add files

func (*Message) AttacheReader added in v1.0.5

func (m *Message) AttacheReader(r io.Reader, filename string) error

AttacheReader - add file from reader

func (*Message) SetBCC

func (m *Message) SetBCC(emails ...string) *Message

SetBCC - field mail secret copy

func (*Message) SetCC

func (m *Message) SetCC(emails ...string) *Message

SetCC - field mail copy

func (*Message) SetFrom

func (m *Message) SetFrom(from string) *Message

SetFrom - from who, self email

func (*Message) SetHTML added in v1.0.6

func (m *Message) SetHTML(body string) *Message

SetHTML - text html

func (*Message) SetSubject

func (m *Message) SetSubject(subj string) *Message

SetSubject - set subkect mail

func (*Message) SetTO

func (m *Message) SetTO(emails ...string) *Message

SetTO - field mail to

func (*Message) SetText

func (m *Message) SetText(body string) *Message

SetText - text body

func (Message) WriteTo added in v1.0.6

func (m Message) WriteTo(w io.Writer) (int64, error)

WriteTo - io.WriteTo

type Sender

type Sender struct {
	Login, Email, Password, ServerSMTP string
}

Sender - smtp client structure

func NewSender

func NewSender(login, password, email, server string) (s *Sender)

NewSender - new smtp client

func (*Sender) SendMessage added in v1.0.6

func (s *Sender) SendMessage(message *Message) error

SendMessage - отправить письмо

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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