emailer

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 13 Imported by: 0

README

emailer

Tiny lib for email (with attachments) sending (smtp, only login auth is supported now)

import

import "github.com/NGRsoftlab/ngr-emailer"

example

s := NewSender(
		"user@mail.com",
		"password",
		"user@mail.com",
		fmt.Sprintf("%v:%v", "test.com", "587"),
	)

		err := s.NewMessage(
		&MessageParams{
			Topic:       "topic",
			ContentType: HtmlContentType,
			Charset:     Utf8Charset,
			Recipients:  []string{"user@test.ru"},
			Body:        body,
			Files: []AttachData{{
				FileName: "test.txt",
				FileData: []byte("test"),
			}},
		})
	if err != nil {
		log.Fatal(err)
	}
	err = s.Send()
	if err != nil {
		log.Fatal(err)
	}

Documentation

Overview

Copyright 2020-2023 NGR Softlab

Copyright 2020-2023 NGR Softlab

Index

Constants

View Source
const (
	HtmlContentType           = "text/html"
	PlainTextContentType      = "plain/text"
	MultipartMixedContentType = "multipart/mixed"
	VndSheetContentType       = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)

Content types

View Source
const (
	Utf8Charset   = "utf-8"
	Base64Charset = "base64"
)

Charsets

Variables

This section is empty.

Functions

func LoginAuth

func LoginAuth(username, password string) smtp.Auth

LoginAuth auth with login and password

func TestLoginAuth added in v1.2.0

func TestLoginAuth(
	host string, port int,
	tlsOn bool, tlsConfig *tls.Config,
	user, password string,
	connTimeout time.Duration) (connError error, authError error)

TestLoginAuth - test smtp server login auth

Types

type AttachData

type AttachData struct {
	FileName string
	FileData []byte
}

AttachData struct for attachments

type MessageParams added in v1.1.0

type MessageParams struct {
	Topic       string
	ContentType string
	Charset     string
	Recipients  []string
	Body        string
	Files       []AttachData
}

type Sender

type Sender struct {
	Auth smtp.Auth

	Login    string // user login
	Password string // user password

	ServerSMTP string // smtp server string (full)
	ServerAddr string // smtp server addr string

	Email string // user email address (from)
	// contains filtered or unexported fields
}

Sender struct - sender for sending smtp packs

func NewSender

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

NewSender creating new *Sender obj

func NewTLSSender added in v1.2.4

func NewTLSSender(auth smtp.Auth, tlsCfg *tls.Config, email, hostAddress, fullServerAddress string) (*Sender, error)

NewTLSSender creating new *Sender obj

func (*Sender) NewMessage

func (s *Sender) NewMessage(params *MessageParams) error

NewMessage creating new email message

func (*Sender) Send

func (s *Sender) Send() error

Send send smtp pack (mail) with login auth

func (*Sender) SendViaClient added in v1.2.4

func (s *Sender) SendViaClient() error

SendViaClient send smtp pack (mail)

func (*Sender) SendWithAuth added in v1.2.0

func (s *Sender) SendWithAuth(auth smtp.Auth) error

SendWithAuth send smtp pack (mail) with custom auth

Jump to

Keyboard shortcuts

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