forked from SimePel/asu-billing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.go
54 lines (43 loc) · 1.17 KB
/
mail.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 (
"fmt"
"net/smtp"
)
func confirmEmail(recipient, url string) error {
return sendEmail(recipient, "Подтверждение email адреса",
"Перейдите по данной ссылке, чтобы подтвердить ваш email.\r\n"+url)
}
func sendEmail(recipient, subject, message string) error {
c, err := smtp.Dial("mail.asu.ru:25")
if err != nil {
return fmt.Errorf("Cannot dial with mail server: %v", err)
}
err = c.Mail("[email protected]")
if err != nil {
return fmt.Errorf("Cannot set from address: %v", err)
}
err = c.Rcpt(recipient)
if err != nil {
return fmt.Errorf("Cannot set recipient address: %v", err)
}
wc, err := c.Data()
if err != nil {
return fmt.Errorf("Cannot get data stream: %v", err)
}
msg := "To: " + recipient + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" + message + "\r\n"
_, err = fmt.Fprint(wc, msg)
if err != nil {
return fmt.Errorf("Cannot fprint to data stream: %v", err)
}
err = wc.Close()
if err != nil {
return fmt.Errorf("Cannot close data stream: %v", err)
}
err = c.Quit()
if err != nil {
return fmt.Errorf("Cannot send quit message: %v", err)
}
return nil
}