emailer

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 9 Imported by: 0

README

emailer

Tiny lib for email (with attachments) sending (smtp)

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

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 {
	Login      string // user login
	Email      string // user email address
	Password   string // user password
	ServerSMTP string // smtp server string
	// 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 (*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)

Jump to

Keyboard shortcuts

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