mirror of
https://github.com/harness-community/drone-email.git
synced 2026-06-04 18:24:18 +08:00
Make attachments optional (#31)
Don't fail if a attachment file doesn't exist.
This commit is contained in:
committed by
Michael de Wit
parent
17393400a4
commit
44396c108b
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/drone/drone-go/template"
|
||||
"github.com/jaytaylor/html2text"
|
||||
"gopkg.in/gomail.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -201,11 +202,11 @@ func (p Plugin) Exec() error {
|
||||
message.AddAlternative("text/html", html)
|
||||
|
||||
if p.Config.Attachment != "" {
|
||||
message.Attach(p.Config.Attachment)
|
||||
attach(message, p.Config.Attachment)
|
||||
}
|
||||
|
||||
for _, attachment := range p.Config.Attachments {
|
||||
message.Attach(attachment)
|
||||
attach(message, attachment)
|
||||
}
|
||||
|
||||
if err := gomail.Send(closer, message); err != nil {
|
||||
@@ -217,3 +218,9 @@ func (p Plugin) Exec() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attach(message *gomail.Message, attachment string) {
|
||||
if _, err := os.Stat(attachment); err == nil {
|
||||
message.Attach(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user