Continued e-mail support
This commit is contained in:
parent
6b46eb46e2
commit
f553cdb282
10 changed files with 132 additions and 10 deletions
|
@ -8,14 +8,14 @@ import (
|
|||
)
|
||||
|
||||
type mailer interface {
|
||||
Send(to string, m *message) error
|
||||
Send(from, to string, m *message) error
|
||||
}
|
||||
|
||||
type smtpMailer struct {
|
||||
config *Config
|
||||
}
|
||||
|
||||
func (s *smtpMailer) Send(to string, m *message) error {
|
||||
func (s *smtpMailer) Send(from, to string, m *message) error {
|
||||
host, _, err := net.SplitHostPort(s.config.SMTPAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -26,10 +26,18 @@ func (s *smtpMailer) Send(to string, m *message) error {
|
|||
}
|
||||
subject += " - " + m.Topic
|
||||
subject = strings.ReplaceAll(strings.ReplaceAll(subject, "\r", ""), "\n", " ")
|
||||
message := m.Message
|
||||
if len(m.Tags) > 0 {
|
||||
message += "\nTags: " + strings.Join(m.Tags, ", ") // FIXME emojis
|
||||
}
|
||||
if m.Priority != 0 && m.Priority != 3 {
|
||||
message += fmt.Sprintf("\nPriority: %d", m.Priority) // FIXME to string
|
||||
}
|
||||
message += fmt.Sprintf("\n\n--\nMessage was sent via %s by client %s", m.Topic, from) // FIXME short URL
|
||||
msg := []byte(fmt.Sprintf("From: %s\r\n"+
|
||||
"To: %s\r\n"+
|
||||
"Subject: %s\r\n\r\n"+
|
||||
"%s\r\n", s.config.SMTPFrom, to, subject, m.Message))
|
||||
"%s\r\n", s.config.SMTPFrom, to, subject, message))
|
||||
auth := smtp.PlainAuth("", s.config.SMTPUser, s.config.SMTPPass, host)
|
||||
return smtp.SendMail(s.config.SMTPAddr, auth, s.config.SMTPFrom, []string{to}, msg)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue