-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (47 loc) · 939 Bytes
/
main.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
package main
import (
"encoding/csv"
"io"
"os"
"send_email_go/mailers"
)
//User is for save information from csv
type User struct {
Name string
Email string
}
type Response struct {
Status bool `json:"status"`
Error string `json:"error"`
}
func main() {
users, _ := parseUser("./user.csv")
for _, user := range users {
subject := "Prueba Sunapp es gratis"
receiver := []string{user.Email}
r := mailers.NewRequest(receiver, subject)
r.Send("templates/template.html", map[string]string{"username": user.Name})
}
}
func parseUser(file string) (map[string]*User, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
csvr := csv.NewReader(f)
locations := map[string]*User{}
for {
row, err := csvr.Read()
if err != nil {
if err == io.EOF {
err = nil
}
return locations, err
}
p := &User{}
p.Name = row[0]
p.Email = row[1]
locations[row[0]] = p
}
}