1
0

Add test mail command (#571)

Add test mail command

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/571
This commit is contained in:
konrad
2020-05-29 13:10:06 +00:00
parent 9ea1104764
commit c685250c96
3 changed files with 77 additions and 3 deletions

View File

@ -27,6 +27,16 @@ import (
// Queue is the mail queue
var Queue chan *gomail.Message
func getDialer() *gomail.Dialer {
d := gomail.NewDialer(config.MailerHost.GetString(), config.MailerPort.GetInt(), config.MailerUsername.GetString(), config.MailerPassword.GetString())
// #nosec
d.TLSConfig = &tls.Config{
InsecureSkipVerify: config.MailerSkipTLSVerify.GetBool(),
ServerName: config.MailerHost.GetString(),
}
return d
}
// StartMailDaemon starts the mail daemon
func StartMailDaemon() {
Queue = make(chan *gomail.Message, config.MailerQueuelength.GetInt())
@ -41,9 +51,7 @@ func StartMailDaemon() {
}
go func() {
d := gomail.NewDialer(config.MailerHost.GetString(), config.MailerPort.GetInt(), config.MailerUsername.GetString(), config.MailerPassword.GetString())
// #nosec
d.TLSConfig = &tls.Config{InsecureSkipVerify: config.MailerSkipTLSVerify.GetBool()}
d := getDialer()
var s gomail.SendCloser
var err error

View File

@ -53,6 +53,30 @@ type header struct {
Content string
}
// SendTestMail sends a test mail to a receipient.
// It works without a queue.
func SendTestMail(to string) error {
if config.MailerHost.GetString() == "" {
log.Warning("Mailer seems to be not configured! Please see the config docs for more details.")
return nil
}
d := getDialer()
s, err := d.Dial()
if err != nil {
return err
}
defer s.Close()
m := gomail.NewMessage()
m.SetHeader("From", config.MailerFromEmail.GetString())
m.SetHeader("To", to)
m.SetHeader("Subject", "Test from Vikunja")
m.SetBody("text/plain", "This is a test mail! If you got this, Vikunja is correctly set up to send emails.")
return gomail.Send(s, m)
}
// SendMail puts a mail in the queue
func SendMail(opts *Opts) {
m := gomail.NewMessage()