Make attachments optional (#31)
Don't fail if a attachment file doesn't exist.
This commit is contained in:
parent
17393400a4
commit
44396c108b
11
plugin.go
11
plugin.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/drone/drone-go/template"
|
"github.com/drone/drone-go/template"
|
||||||
"github.com/jaytaylor/html2text"
|
"github.com/jaytaylor/html2text"
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -201,11 +202,11 @@ func (p Plugin) Exec() error {
|
||||||
message.AddAlternative("text/html", html)
|
message.AddAlternative("text/html", html)
|
||||||
|
|
||||||
if p.Config.Attachment != "" {
|
if p.Config.Attachment != "" {
|
||||||
message.Attach(p.Config.Attachment)
|
attach(message, p.Config.Attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, attachment := range p.Config.Attachments {
|
for _, attachment := range p.Config.Attachments {
|
||||||
message.Attach(attachment)
|
attach(message, attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gomail.Send(closer, message); err != nil {
|
if err := gomail.Send(closer, message); err != nil {
|
||||||
|
@ -217,3 +218,9 @@ func (p Plugin) Exec() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func attach(message *gomail.Message, attachment string) {
|
||||||
|
if _, err := os.Stat(attachment); err == nil {
|
||||||
|
message.Attach(attachment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue