-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.go
87 lines (77 loc) · 2.33 KB
/
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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"log"
"math/rand"
"net/smtp"
)
func send(rcpt, text string) {
log.Println(text)
/*
fmt.Println(text)
fmt.Println("Email sent")
return
*/
// Connect to the remote SMTP server.
c, err := smtp.Dial("smtp.hm.com:25")
if err != nil {
log.Fatal(err)
}
// Set the sender and recipient first
if err := c.Mail("[email protected]"); err != nil {
log.Fatal(err)
}
if err := c.Rcpt(rcpt); err != nil {
log.Fatal(err)
}
// Send the email body.
wc, err := c.Data()
if err != nil {
log.Fatal(err)
}
from := fmt.Sprintf("From: <%s>\r\n", "[email protected]")
to := fmt.Sprintf("To: <%s>\r\n", rcpt)
subject := "Subject: " + "Namespace deletion -- " + getRandLine() + "\r\n"
body := text + "\r\n"
msg := from + to + subject + "\r\n" + body
_, err = fmt.Fprintf(wc, msg)
if err != nil {
log.Fatal(err)
}
err = wc.Close()
if err != nil {
log.Fatal(err)
}
// Send the QUIT command and close the connection.
err = c.Quit()
if err != nil {
log.Fatal(err)
}
}
func getRandLine() string {
quotes := []string{
"It is always important to know when something has reached its end",
"There is no real ending",
"A man is like a novel: until the very last page you don't know how it will end",
"Ends are not bad things, they just mean that something else is about to begin",
"There's a trick to the 'graceful exit",
"Build your life on your dreams; because dreams never have bad endings",
"We lose the precious sense that an end is only a beginning in disguise",
"Every ending is a beginning",
"An end is only a beginning in disguise",
"A sunset is nothing more and nothing less than the backside of a sunrise",
"It all begins and ends in your mind",
"I try to avoid stories that end with",
"There should have been a better farewell",
"There is always more after the ending",
"A moment's beginning ends in a moment",
"The great miraculous bell of translucent ice is suspended in mid-air",
"Endings to be useful must be inconclusive",
"It's a lot easier to say when something ended rather than when it began",
"The feeling is less like an ending than just another starting point",
"I may regret the way we ended, but I will never regret what we had",
"It's much easier to not know things sometimes",
"Everything has to come to an end, sometime",
}
return quotes[rand.Intn(len(quotes))]
}