-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpongo2-template.go
65 lines (62 loc) · 1.61 KB
/
pongo2-template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/flosch/pongo2"
"io"
"os/exec"
"log"
)
func constructemail(message string, from string, to string, subject string, html bool) string{
var email string
if html{
email = "From: " + from + "\nTo: " + to + "\nSubject: " + subject + "\nMime-Version: 1.0\nContent-Type: text/html\n" + message +"\n."
}else{
email = "From: " + from + "\nTo: " + to + "\nSubject: " + subject + "\n" + message +"\n."
}
return email
}
func sendmail(email string, to string){
cmd:= exec.Command("sendmail", to)
// Executes returns command struct to execute the program.
stdin, err :=cmd.StdinPipe()
//Creates a pipe to the command line
if err!=nil{
log.Fatal(err)
}
go func(){
defer stdin.Close()
io.WriteString(stdin, email)
}()
//Runs the command
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
}
func main(){
tmpl, err := pongo2.FromString("Hello {{ name|capfirst }}! How was the {{ type }} restaurant yesterday?\nDid they have {{ num1 }} or {{ num2 }} courses!?")
if err != nil {
panic(err)
}
output, err := tmpl.Execute(pongo2.Context{"name": "florian", "type": "mexican", "num1":1, "num2":2 })
if err != nil {
panic(err)
}
message := output
cmd:= exec.Command("sendmail", "villasenor.ariel@gmail.com")
stdin, err :=cmd.StdinPipe()
if err!=nil{
log.Fatal(err)
}
go func(){
defer stdin.Close()
email := "From: arielv@msi-GT70\nTo: villasenor.ariel@gmail.com\nSubject: Test 568\n" + message +"\n."
io.WriteString(stdin, email)
}()
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Println(output)
}