Skip to content

Instantly share code, notes, and snippets.

@asahasrabuddhe
Created September 18, 2018 11:48
Show Gist options
  • Save asahasrabuddhe/20e6c13d405464aa55afd65cba5d9046 to your computer and use it in GitHub Desktop.
Save asahasrabuddhe/20e6c13d405464aa55afd65cba5d9046 to your computer and use it in GitHub Desktop.
Go Email
package main
import (
"fmt"
"github.com/asahasrabuddhe/pigeon"
"github.com/asahasrabuddhe/pigeon/email"
"github.com/asahasrabuddhe/pigeon/smtp"
"github.com/asahasrabuddhe/pigeon/themes/default"
"github.com/asahasrabuddhe/pigeon/themes/flat"
)
type example interface {
Name() string
Email() email.Email
}
func main() {
m := smtp.NewMessage()
m.SetHeader("From", "ajitem.sahasrabuddhe@perennialsys.com")
m.SetAddressHeader("To", "mohasin.kazi@perennialsys.com", "Mohasin Kazi")
//m.SetAddressHeader("Cc", "trunal.thakre@perennialsys.com", "Trunal Thakre")
p := pigeon.Pigeon{
Product: pigeon.Product{
Name: "Pigeon",
Link: "https://golang.org/",
Logo: "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png",
},
}
var themes = []pigeon.Theme {
new(flat.Flat),
new(default_theme.Default),
}
var emails = []example {
new(welcome),
new(forgotPassword),
new(invoice),
}
for _, t := range themes {
for _, mail := range emails {
p.Theme = t
s, _ := p.GenerateHTML(mail.Email())
m.SetHeader("Subject", mail.Name())
m.SetBody("text/html", s)
//imageHeader := map[string][]string{"Content-Type": {"image/png"}}
//m.Embed("/home/ajitem/Pictures/nZVkm8ibo3OJz7DBlIpZdR0nZ5G4TGuU69dGoBul97E.png", smtp.SetHeader(imageHeader))
//pdfHeader := map[string][]string{"Content-Type": {"application/pdf"}}
//m.Attach("/home/ajitem/Downloads/Greg_Kroah-Hartman_-_Linux_Kernel_in_a_Nutshell.pdf", smtp.SetHeader(pdfHeader))
d := smtp.NewDialer("smtp.gmail.com", 587, "ajitem.sahasrabuddhe@perennialsys.com", "pass")
// Send the email.
if err := d.DialAndSend(m); err != nil {
panic(err)
} else {
fmt.Println("Mail sent successfully")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment