Compare commits
2 Commits
39396ac0bf
...
22d1737a8d
Author | SHA1 | Date |
---|---|---|
Sameer Rahmani | 22d1737a8d | |
Sameer Rahmani | c01f050e15 |
|
@ -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
|
|
@ -0,0 +1,7 @@
|
|||
TAG=4
|
||||
|
||||
build:
|
||||
docker build -t lxsameer/woodpecker_mailer:$(TAG) .
|
||||
|
||||
push:
|
||||
docker push lxsameer/woodpecker_mailer:$(TAG)
|
21
README.md
21
README.md
|
@ -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}
|
||||
```
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/mail"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// "Send As" information
|
||||
|
||||
func main() {
|
||||
var (
|
||||
username = os.Getenv("PLUGIN_USER")
|
||||
password = os.Getenv("PLUGIN_PASSWORD")
|
||||
to = os.Getenv("PLUGIN_TO")
|
||||
subject = os.Getenv("PLUGIN_SUBJECT")
|
||||
body = os.Getenv("PLUGIN_TEXT")
|
||||
from_addr = os.Getenv("PLUGIN_FROM")
|
||||
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)
|
||||
|
||||
fmt.Println("Authenticateing...")
|
||||
auth := smtp.PlainAuth("", username, password, "smtp.gmail.com")
|
||||
smtpConnection, err := smtp.Dial(gmail)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := smtpConnection.StartTLS(&tls.Config{ServerName: "smtp.gmail.com"}); err != nil {
|
||||
|
||||
panic(err)
|
||||
}
|
||||
if err := smtpConnection.Auth(auth); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
from := mail.Address{Name: from_name, Address: from_addr}
|
||||
|
||||
header := make(map[string]string)
|
||||
header["From"] = from.String()
|
||||
header["To"] = to
|
||||
header["Subject"] = subject
|
||||
|
||||
// Convert the header map to a string and attach the body to it
|
||||
var message string
|
||||
for key, value := range header {
|
||||
message += fmt.Sprintf("%s: %s\r\n", key, value)
|
||||
}
|
||||
message += "\r\n" + sanitizedBody + "\r\n"
|
||||
|
||||
fmt.Println("Senting an email to user")
|
||||
|
||||
rcpts := strings.Split(to, ",")
|
||||
err = smtp.SendMail(gmail, auth, from_addr, rcpts, []byte(message))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
smtpConnection.Quit()
|
||||
fmt.Println("Done")
|
||||
}
|
Loading…
Reference in New Issue