-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.go
36 lines (27 loc) · 803 Bytes
/
email.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
package main
import (
"fmt"
"time"
gomail "gopkg.in/gomail.v2"
)
func sendEmail(toWork bool) {
m := gomail.NewMessage()
email := parameters().emailAddress
password := parameters().emailPassword
username := parameters().name
now := time.Now()
noon := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, now.Location())
m.SetHeader("From", email)
m.SetHeader("To", email)
m.SetHeader("Subject", "Commute report for "+now.Format("Mon Jan 2"))
m.SetBody("text/html", fmt.Sprintf("Hi %s,<br>Here's your commute information for %s:<br><br>", username, timeOfDay(now, noon)))
if toWork {
m.Attach(toWorkFilename)
} else {
m.Attach(fromWorkFilename)
}
d := gomail.NewDialer("smtp.gmail.com", 587, email, password)
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}