gte/cmd/cli/command/send.go

37 lines
724 B
Go
Raw Normal View History

2021-09-03 09:31:41 +02:00
package command
import (
"fmt"
2024-03-08 09:20:40 +01:00
"code.ewintr.nl/gte/cmd/cli/format"
"code.ewintr.nl/gte/internal/configuration"
"code.ewintr.nl/gte/internal/process"
"code.ewintr.nl/gte/internal/storage"
"code.ewintr.nl/gte/pkg/msend"
2021-09-03 09:31:41 +02:00
)
type Send struct {
sender *process.Send
}
func NewSend(conf *configuration.Configuration) (*Send, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Send{}, err
}
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
return &Send{
sender: process.NewSend(local, disp),
}, nil
}
func (s *Send) Do() string {
count, err := s.sender.Process()
if err != nil {
return format.FormatError(err)
}
2021-09-04 19:47:36 +02:00
return fmt.Sprintf("sent %d tasks\n\n", count)
2021-09-03 09:31:41 +02:00
}