github.com/unclejack/drone@v0.2.1-0.20140918182345-831b034aa33b/pkg/plugin/notify/email.go (about) 1 package notify 2 3 import "github.com/drone/drone/pkg/mail" 4 5 type Email struct { 6 Recipients []string `yaml:"recipients,omitempty"` 7 Success string `yaml:"on_success"` 8 Failure string `yaml:"on_failure"` 9 } 10 11 // Send will send an email, either success or failure, 12 // based on the Commit Status. 13 func (e *Email) Send(context *Context) error { 14 switch { 15 case context.Commit.Status == "Success" && e.Success != "never": 16 return e.sendSuccess(context) 17 case context.Commit.Status == "Failure" && e.Failure != "never": 18 return e.sendFailure(context) 19 } 20 21 return nil 22 } 23 24 // sendFailure sends email notifications to the list of 25 // recipients indicating the build failed. 26 func (e *Email) sendFailure(context *Context) error { 27 // loop through and email recipients 28 for _, email := range e.Recipients { 29 if err := mail.SendFailure(context.Repo.Name, context.Commit.HashShort(), email, context); err != nil { 30 return err 31 } 32 } 33 return nil 34 } 35 36 // sendSuccess sends email notifications to the list of 37 // recipients indicating the build was a success. 38 func (e *Email) sendSuccess(context *Context) error { 39 // loop through and email recipients 40 for _, email := range e.Recipients { 41 if err := mail.SendSuccess(context.Repo.Name, context.Commit.HashShort(), email, context); err != nil { 42 return err 43 } 44 } 45 return nil 46 }