-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity.go
47 lines (38 loc) · 1.18 KB
/
activity.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
package sendmail
import (
"log"
"net/smtp"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
)
// MyActivity is a stub for your Activity implementation
type MyActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new activity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &MyActivity{metadata: metadata}
}
// Metadata implements activity.Activity.Metadata
func (a *MyActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements activity.Activity.Eval
func (a *MyActivity) Eval(context activity.Context) (done bool, err error) {
// set inputs
to := context.GetInput("to").(string)
from := context.GetInput("from").(string)
password := context.GetInput("password").(string)
subject := context.GetInput("subject").(string)
message := context.GetInput("message").(string)
// do eval
body := "To: " + to + "\r\nSubject: " +
subject + "\r\n\r\n" + message
auth := smtp.PlainAuth("", from, password, "smtp.gmail.com")
err = smtp.SendMail("smtp.gmail.com:587", auth, from,
[]string{to}, []byte(body))
context.SetOutput("result", "The email has been sent to "+to)
if err != nil {
log.Fatal(err)
}
return true, nil
}