first release

This commit is contained in:
Sameer Rahmani 2023-05-13 18:16:33 +01:00
parent c01f050e15
commit 22d1737a8d
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
4 changed files with 55 additions and 4 deletions

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM alpine
RUN apk --no-cache add go ca-certificates
WORKDIR /app
ADD go.mod .
ADD main.go .
RUN go build main.go
RUN ls main
FROM alpine
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=0 /app/main /app/main
ENTRYPOINT /app/main

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
TAG=4
build:
docker build -t lxsameer/woodpecker_mailer:$(TAG) .
push:
docker push lxsameer/woodpecker_mailer:$(TAG)

View File

@ -1,3 +1,22 @@
# woodpecker_mailer
This is a very basic mailer plugin for woodpecker
A mailer plugin for the Woodpecker CI.
Example configuration:
```yaml
pipeline:
Mail:
image: lxsameer/woodpecker_mailer:4
settings:
from: ci@serene-lang.org
user:
from_secret: mail_user
password:
from_secret: mail_pass
to: ${CI_COMMIT_AUTHOR_EMAIL}
subject: "[${CI_REPO}] JOB #${CI_BUILD_NUMBER} - ${CI_PREV_STEP_STATUS}"
text: |
BUILD: ${CI_BUILD_LINK}
COMMIT: ${CI_COMMIT_LINK}
```

17
main.go
View File

@ -7,6 +7,7 @@ import (
"net/mail"
"net/smtp"
"os"
"strings"
)
// "Send As" information
@ -22,6 +23,14 @@ func main() {
from_name = os.Getenv("PLUGIN_FROM_NAME")
)
if username == "" || password == "" || to == "" || subject == "" || body == "" {
panic("'user', 'password', 'to', 'subject', and 'text' are mandatory!")
}
if username == "" || password == "" || to == "" || subject == "" || body == "" {
panic("'user', 'password', 'to', 'subject', and 'text' are mandatory!")
}
const gmail = "smtp.gmail.com:587"
sanitizedBody := template.HTMLEscapeString(body)
@ -41,11 +50,10 @@ func main() {
}
from := mail.Address{Name: from_name, Address: from_addr}
rcpt := mail.Address{Name: "", Address: to}
header := make(map[string]string)
header["From"] = from.String()
header["To"] = rcpt.String()
header["To"] = to
header["Subject"] = subject
// Convert the header map to a string and attach the body to it
@ -56,10 +64,13 @@ func main() {
message += "\r\n" + sanitizedBody + "\r\n"
fmt.Println("Senting an email to user")
err = smtp.SendMail(gmail, auth, from_addr, []string{rcpt.Address}, []byte(message))
rcpts := strings.Split(to, ",")
err = smtp.SendMail(gmail, auth, from_addr, rcpts, []byte(message))
if err != nil {
panic(err)
}
smtpConnection.Quit()
fmt.Println("Done")
}