2021-12-17 04:54:03 +00:00
|
|
|
package email
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"gopkg.in/gomail.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// viper.SetDefault("email.type", "smtp")
|
|
|
|
viper.SetDefault("email.host", "mail.kumoly.io")
|
|
|
|
viper.SetDefault("email.port", 587)
|
|
|
|
viper.SetDefault("email.username", "test@kumoly.io")
|
|
|
|
viper.SetDefault("email.password", "test")
|
2021-12-17 08:22:04 +00:00
|
|
|
viper.SetDefault("logo", "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png")
|
2021-12-17 04:54:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 07:52:32 +00:00
|
|
|
type App struct {
|
|
|
|
Name string
|
|
|
|
Link string
|
|
|
|
Logo string
|
|
|
|
Copyright string
|
|
|
|
}
|
|
|
|
|
2021-12-24 05:31:33 +00:00
|
|
|
type Button struct {
|
|
|
|
Text string
|
|
|
|
Link string
|
|
|
|
|
|
|
|
// Color of the button, default blue(#3869D4)
|
|
|
|
Color string
|
|
|
|
// TextColor of the button, default blue(#ffffff)
|
|
|
|
TextColor string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Action struct {
|
|
|
|
// Instructions text show before button
|
|
|
|
Instructions string
|
|
|
|
|
|
|
|
// InviteCode should not be used with button
|
|
|
|
InviteCode string
|
|
|
|
Button Button
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:52:32 +00:00
|
|
|
type Body struct {
|
2021-12-17 08:22:04 +00:00
|
|
|
// App replaced with global config
|
|
|
|
App App
|
|
|
|
|
2021-12-17 07:52:32 +00:00
|
|
|
Intros []string
|
|
|
|
Content string
|
2021-12-17 08:22:04 +00:00
|
|
|
Outros []string
|
2021-12-17 07:52:32 +00:00
|
|
|
|
2021-12-24 05:31:33 +00:00
|
|
|
Actions []Action
|
|
|
|
|
2021-12-17 08:22:04 +00:00
|
|
|
// Greeting ignored if empty
|
2021-12-17 07:52:32 +00:00
|
|
|
Greeting string
|
2021-12-17 08:22:04 +00:00
|
|
|
// Receiver ignored if Greeting or Receiver empty
|
2021-12-17 07:52:32 +00:00
|
|
|
Receiver string
|
|
|
|
|
2021-12-17 08:22:04 +00:00
|
|
|
// Signature default `Best Regards`
|
2021-12-17 07:52:32 +00:00
|
|
|
Signature string
|
2021-12-17 08:22:04 +00:00
|
|
|
// Sender default {{.App.Name}}
|
|
|
|
Sender string
|
2021-12-17 07:52:32 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 04:54:03 +00:00
|
|
|
// host string, port int, username string, password string
|
|
|
|
var dial *gomail.Dialer
|
|
|
|
|
|
|
|
func Send(From string, To []string, Title string, b *Body) error {
|
|
|
|
|
|
|
|
m := gomail.NewMessage()
|
|
|
|
m.SetHeader("From", From)
|
|
|
|
m.SetHeader("To", To...)
|
|
|
|
m.SetHeader("Subject", Title)
|
|
|
|
// m.SetAddressHeader("Cc", "dan@example.com", "Dan")
|
|
|
|
// m.Attach("/home/Alex/lolcat.jpg")
|
|
|
|
|
|
|
|
body, err := Parse(b)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.SetBody("text/html", body)
|
|
|
|
|
|
|
|
// Send the email
|
|
|
|
return dial.DialAndSend(m)
|
|
|
|
}
|