100 lines
2.0 KiB
Go
100 lines
2.0 KiB
Go
|
package emailer
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"time"
|
|||
|
|
|||
|
"gopkg.in/gomail.v2"
|
|||
|
)
|
|||
|
|
|||
|
func init() {
|
|||
|
|
|||
|
app.Name = "Kumoly Test"
|
|||
|
app.Copyright = fmt.Sprintf("Copyright © %v %s. All rights reserved.",
|
|||
|
time.Now().Year(), app.Name)
|
|||
|
app.Link = "https://kumoly.io"
|
|||
|
app.Logo = "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png"
|
|||
|
app.TroubleText = "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser."
|
|||
|
dial = gomail.NewDialer("mail.kumoly.io", 587, "test@kumoly.io", "test")
|
|||
|
}
|
|||
|
|
|||
|
type App struct {
|
|||
|
Name string
|
|||
|
Link string
|
|||
|
Logo string
|
|||
|
Copyright string
|
|||
|
TroubleText string
|
|||
|
Theme string
|
|||
|
TitleColor string
|
|||
|
FooterColor string
|
|||
|
}
|
|||
|
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
type Body struct {
|
|||
|
// App replaced with global config
|
|||
|
App App
|
|||
|
|
|||
|
Intros []string
|
|||
|
Content string
|
|||
|
Outros []string
|
|||
|
|
|||
|
Actions []Action
|
|||
|
|
|||
|
// Greeting ignored if empty
|
|||
|
Greeting string
|
|||
|
// Receiver ignored if Greeting or Receiver empty
|
|||
|
Receiver string
|
|||
|
|
|||
|
// Signature default `Best Regards`
|
|||
|
Signature string
|
|||
|
// Sender default {{.App.Name}}
|
|||
|
Sender string
|
|||
|
}
|
|||
|
|
|||
|
// 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)
|
|||
|
}
|
|||
|
|
|||
|
func SetDefault(a App) {
|
|||
|
app = a
|
|||
|
}
|
|||
|
|
|||
|
func SetDailer(d *gomail.Dialer) {
|
|||
|
dial = d
|
|||
|
}
|