Created
September 18, 2018 11:48
-
-
Save asahasrabuddhe/20e6c13d405464aa55afd65cba5d9046 to your computer and use it in GitHub Desktop.
Go Email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "[email protected]") | |
m.SetAddressHeader("To", "[email protected]", "Mohasin Kazi") | |
//m.SetAddressHeader("Cc", "[email protected]", "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, "[email protected]", "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