-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendemail.go
49 lines (40 loc) · 1000 Bytes
/
sendemail.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
package mail
import (
"log"
"net/smtp"
"github.com/Tympanix/artoodetoo/unit"
)
// SendEmail mimcs sending an email as an action
type SendEmail struct {
Receiver string `io:"input"`
Subject string `io:"input"`
Message string `io:"input"`
}
func init() {
unit.Register(&SendEmail{})
}
// Describe describes what an email action does
func (a *SendEmail) Describe() string {
return "Sends an E-mail to a chosen receiver with a chosen subject and message"
}
// Execute sends the email
func (a *SendEmail) Execute() error {
auth := smtp.PlainAuth(
"iAutomaton",
"iautomaton1@gmail.com",
"iautomaton",
"smtp.gmail.com",
)
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
to := []string{a.Receiver}
msg := []byte(
"Subject: " + a.Subject + "\r\n" +
"\r\n" +
a.Message + "\r\n")
if err := smtp.SendMail("smtp.gmail.com:25", auth, "hmm", to, msg); err != nil {
log.Fatal(err)
return err
}
return nil
}