mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
E-mail through linux command with UseCommand configuration field
This commit is contained in:
parent
b58c16113a
commit
679b707751
|
@ -22,3 +22,8 @@ type Mail struct {
|
|||
func DefaultMail() Mail {
|
||||
return Mail{}
|
||||
}
|
||||
|
||||
// IsValid returns true if the mail configs are valid
|
||||
func (m Mail) IsValid() bool {
|
||||
return (m.Host != "" && m.Port > 0 && m.Username != "" && m.Password != "") || m.UseCommand
|
||||
}
|
||||
|
|
2
iris.go
2
iris.go
|
@ -176,7 +176,7 @@ func (s *Iris) initWebsocketServer() {
|
|||
func (s *Iris) initMailService() {
|
||||
if s.mailService == nil {
|
||||
// enable mail sender service if configs are valid
|
||||
if s.config.Mail.Host != "" && s.config.Mail.Username != "" && s.config.Mail.Password != "" {
|
||||
if s.config.Mail.IsValid() {
|
||||
s.mailService = mail.New(s.config.Mail)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ func (m *mailer) sendSMTP(to []string, subject, body string) error {
|
|||
defer buf.Put(buffer)
|
||||
|
||||
if !m.authenticated {
|
||||
if m.config.Username == "" || m.config.Password == "" || m.config.Host == "" {
|
||||
return fmt.Errorf("Username, Password, Host cannot be empty when using SMTP!")
|
||||
if m.config.Username == "" || m.config.Password == "" || m.config.Host == "" || m.config.Port <= 0 {
|
||||
return fmt.Errorf("Username, Password, Host & Port cannot be empty when using SMTP!")
|
||||
}
|
||||
m.auth = smtp.PlainAuth("", m.config.Username, m.config.Password, m.config.Host)
|
||||
m.authenticated = true
|
||||
|
@ -75,7 +75,7 @@ func (m *mailer) sendSMTP(to []string, subject, body string) error {
|
|||
func (m *mailer) sendCmd(to []string, subject, body string) error {
|
||||
buffer := buf.Get()
|
||||
defer buf.Put(buffer)
|
||||
// buffer.WriteString(body)
|
||||
|
||||
cmd := utils.CommandBuilder("mail", "-s", subject, strings.Join(to, ","))
|
||||
cmd.AppendArguments("-a", "Content-type: text/html") //always html on
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user