smtp

package module
v0.0.0-...-2a52673 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

README

smtp

Send Mail

Documentation

Index

Constants

View Source
const DAY_NANOSECOND = 24 * 60 * 60 * 1e9
View Source
const HOUR_NANOSECOND = 60 * 60 * 1e9
View Source
const MINUTE_NANOSECOND = 60 * 1e9

Variables

View Source
var CONFIG_PATH = "./config.json"
View Source
var LastRandom = make([]byte, 16)
View Source
var OptionContinueIfDeleteSingleFileError = Option(1)

Functions

func CheckVerificationCode

func CheckVerificationCode(uniqueDesc string, receiver MailAddress, checkCode int) bool

func ClearVerificationCodes

func ClearVerificationCodes()

func Close

func Close() error

func ConfigToDisk

func ConfigToDisk() error

func ConsumeTaskIfNeeded

func ConsumeTaskIfNeeded()

func GenerateVerificationCode

func GenerateVerificationCode(uniqueDesc string, receiver MailAddress) int

func Init

func Init()

func InitTicker

func InitTicker()

func InitVerify

func InitVerify()

func MultiError

func MultiError(errs []error) error

func ResetStorageIndexFromDisk

func ResetStorageIndexFromDisk() error

func ResetVerificationCodes

func ResetVerificationCodes()

func RunEveryMinute

func RunEveryMinute()

func RunEveryTenMinute

func RunEveryTenMinute()

func SendVerificationCode

func SendVerificationCode(projectName string, receiver MailAddress, checkCode int) error

func SendVerificationCodeWithSmtpAndProject

func SendVerificationCodeWithSmtpAndProject(smtp *Smtp, project Project, projectName string, receiver MailAddress, checkCode int) error

func SetConfigPath

func SetConfigPath(path string)

func StorgaeClearIfNeed

func StorgaeClearIfNeed(option Option) error

Types

type Config

type Config struct {
	Smtp    *Smtp   `json:"Smtp"`
	Storgae Storgae `json:"Storgae"`
	Admin   Project `json:"Admin"`

	Passwords map[string]string `json:"Passwords"`

	PenddingTaskSavePath string     `json:"PenddingTaskSavePath"`
	Tasks                []string   `json:"Tasks"`
	TaskQueue            *TaskQueue `json:"-"`

	MailAddressToProjectUniqueKey map[MailAddress][]ProjectUniqueKey `json:"EmailAddressToProjectUniqueKey"`
	Projects                      map[ProjectUniqueKey]*Project      `json:"Projects"`
}

func GetConfig

func GetConfig() *Config

type MailAddress

type MailAddress string

type Option

type Option int32

type Project

type Project struct {
	ProjectUniqueKey ProjectUniqueKey `json:"-"`

	Strategy Strategy `json:"Strategy"`

	Name  string        `json:"Name"`
	Admin []MailAddress `json:"Admin"`

	ReceiverMustMatch string        `json:"ReceiverMustMatch"`
	Receivers         []MailAddress `json:"Receivers"`

	Sender  string `json:"Sender"`
	Subject string `json:"Subject"`
}

func (*Project) AppendToReceivers

func (project *Project) AppendToReceivers(receiver MailAddress)

func (*Project) AppendToReceiversWithCheck

func (project *Project) AppendToReceiversWithCheck(receiver MailAddress) error

func (*Project) ConvertReceiversToStringArray

func (project *Project) ConvertReceiversToStringArray() []string

func (*Project) ExistInReceivers

func (project *Project) ExistInReceivers(receiver MailAddress) bool

func (*Project) ReceiverMatch

func (project *Project) ReceiverMatch(receiver MailAddress) error

func (*Project) Send

func (project *Project) Send(bytes []byte) error

type ProjectUniqueKey

type ProjectUniqueKey string

type Smtp

type Smtp struct {
	WithoutAuth bool `json:"WithoutAuth"`

	Host     string `json:"Host"`
	Port     int    `json:"Port"`
	Username string `json:"Username"`
	Password string `json:"Password"`
}

func (*Smtp) Run

func (s *Smtp) Run(project *Project, html []byte) error

type Storgae

type Storgae struct {
	UsedBytes int64 `json:"-"`

	DataPath         string `json:"DataPath"`
	NeedClearBytes   int64  `json:"NeedClearBytes"`
	NeverExceedBytes int64  `json:"NeverExceedBytes"`
	SavedSecond      int64  `json:"SavedSecond"`

	Index StorgaeIndex `json:"-"`
}

func (*Storgae) ClearBytesUntil

func (storgae *Storgae) ClearBytesUntil(len int64, option Option) error

func (*Storgae) ClearUnixNanoUntil

func (storgae *Storgae) ClearUnixNanoUntil(unixNano int64, option Option) error

func (*Storgae) Delete

func (storgae *Storgae) Delete(item *StorgaeIndexItem) error

func (*Storgae) Init

func (storgae *Storgae) Init() error

func (*Storgae) LoadStorageIndexFromDisk

func (storgae *Storgae) LoadStorageIndexFromDisk() error

func (*Storgae) PrepareByte

func (storgae *Storgae) PrepareByte(len int)

func (*Storgae) Read

func (storgae *Storgae) Read(project *Project) ([]StorgaeHTML, error)

func (*Storgae) Write

func (storgae *Storgae) Write(project *Project, html []byte) error

type StorgaeHTML

type StorgaeHTML struct {
	UnixNano int64  `json:"UnixNano"`
	Hashcode string `json:"Hashcode"`
	Data     []byte `json:"Data"`
}

type StorgaeIndex

type StorgaeIndex struct {
	Items *go_queue.ConcurrentQueue
}

type StorgaeIndexItem

type StorgaeIndexItem struct {
	Task Task  `json:"task"`
	Byte int64 `json:"Byte"`
}

type StorgaeIndexItemArray

type StorgaeIndexItemArray []StorgaeIndexItem

func (StorgaeIndexItemArray) Len

func (array StorgaeIndexItemArray) Len() int

func (StorgaeIndexItemArray) Less

func (array StorgaeIndexItemArray) Less(i, j int) bool

func (StorgaeIndexItemArray) Swap

func (array StorgaeIndexItemArray) Swap(i, j int)

type Strategy

type Strategy struct {
	OnlySendlatest bool   `json:"OnlySendlatest"`
	Merge          bool   `json:"Merge"`
	Close          bool   `json:"Close"`
	Period         string `json:"Period"`
}

func (*Strategy) Allowed

func (strategy *Strategy) Allowed(unixNano int64) bool

func (*Strategy) IsValid

func (strategy *Strategy) IsValid() bool

func (*Strategy) NextSendTime

func (strategy *Strategy) NextSendTime(unixNano int64) int64

type Task

type Task struct {
	ProjectUniqueKey ProjectUniqueKey `json:"ProjectUniqueKey"`
	SendUnixNano     int64            `json:"SendUnixNano"`
	Hashcode         string           `json:"Hashcode"`
	Bytes            []byte           `json:"Bytes"`
}

func (*Task) Execute

func (task *Task) Execute(taskRootpath, storageDataPath string, project *Project, smtp *Smtp) error

type TaskQueue

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

func NewTaskQueue

func NewTaskQueue(tasks []string, path, storgaePath string) (*TaskQueue, error)

func (*TaskQueue) ConsumeTaskIfNeeded

func (taskQueue *TaskQueue) ConsumeTaskIfNeeded(unixNano int64, storageDataPath string, projects map[ProjectUniqueKey]*Project, smtp *Smtp) error

this method can only be called in smtp

func (*TaskQueue) Len

func (taskQueue *TaskQueue) Len() int

func (*TaskQueue) Less

func (taskQueue *TaskQueue) Less(i, j int) bool

func (*TaskQueue) Pop

func (taskQueue *TaskQueue) Pop() interface{}

func (*TaskQueue) PopTask

func (taskQueue *TaskQueue) PopTask() *Task

func (*TaskQueue) Push

func (taskQueue *TaskQueue) Push(x interface{})

func (*TaskQueue) PushTask

func (taskQueue *TaskQueue) PushTask(task *Task)

func (*TaskQueue) SubmitTask

func (taskQueue *TaskQueue) SubmitTask(task *Task) error

func (*TaskQueue) Swap

func (taskQueue *TaskQueue) Swap(i, j int)

func (*TaskQueue) TopTask

func (taskQueue *TaskQueue) TopTask() *Task

Jump to

Keyboard shortcuts

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