Skip to content

Commit

Permalink
cleanup of newman package (#6)
Browse files Browse the repository at this point in the history
* cleanup, ensure interface is met, httpsling, resend tests

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* tabs and spaces :(

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* sonare version

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* one last pass

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* add mock provider

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* handle errors

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

---------

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
  • Loading branch information
golanglemonade authored Sep 5, 2024
1 parent e7ba7d6 commit 5131a45
Show file tree
Hide file tree
Showing 44 changed files with 1,073 additions and 427 deletions.
53 changes: 51 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,58 @@ steps:
command: ["task", "go:lint"]
environment:
- "GOTOOLCHAIN=auto"
- label: ":golang: go test"
key: "go_test"
cancel_on_build_failing: true
plugins:
- docker#v5.11.0:
image: "ghcr.io/theopenlane/build-image:latest"
image: golang:1.23.0
always-pull: true
command: ["task", "go:test"]
command: ["go", "test", "-coverprofile=coverage.out", "./..."]
environment:
- "GOTOOLCHAIN=auto"
artifact_paths: ["coverage.out"]
- group: ":closed_lock_with_key: Security Checks"
depends_on: "go_test"
key: "security"
steps:
- label: ":closed_lock_with_key: gosec"
key: "gosec"
plugins:
- docker#v5.11.0:
image: "registry.hub.docker.com/securego/gosec:2.20.0"
command: ["-no-fail", "-exclude-generated", "-fmt sonarqube", "-out", "results.txt", "./..."]
environment:
- "GOTOOLCHAIN=auto"
artifact_paths: ["results.txt"]
- label: ":github: upload PR reports"
key: "scan-upload-pr"
if: build.pull_request.id != null
depends_on: ["gosec", "go_test"]
plugins:
- artifacts#v1.9.4:
download: "results.txt"
- artifacts#v1.9.4:
download: "coverage.out"
step: "go_test"
- docker#v5.11.0:
image: "sonarsource/sonar-scanner-cli:11.0"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
- "SONAR_SCANNER_OPTS=-Dsonar.pullrequest.branch=$BUILDKITE_BRANCH -Dsonar.pullrequest.base=$BUILDKITE_PULL_REQUEST_BASE_BRANCH -Dsonar.pullrequest.key=$BUILDKITE_PULL_REQUEST"
- label: ":github: upload reports"
key: "scan-upload"
if: build.branch == "main"
depends_on: ["gosec", "go_test"]
plugins:
- artifacts#v1.9.4:
download: results.txt
- artifacts#v1.9.4:
download: coverage.out
step: "go_test"
- docker#v5.11.0:
image: "sonarsource/sonar-scanner-cli:11.0"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ enhancement:
# Add 'breaking-change' label to any PR where the head branch name starts with `breaking-change` or has a `breaking-change` section in the name
breaking-change:
- head-branch: ["^breaking-change", "breaking-change"]
# Add 'dependencies' label to any PR where the head branch name starts with `dependencies` or has a `dependencies` section in the name
dependencies:
- head-branch: ["^dependencies", "dependencies", "^deps", "deps"]
ci:
- changed-files:
- any-glob-to-any-file: .github/**
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ Thumbs.db
*.mime
*.mim

*.env
*.env-dev
*.config.yaml
test/*
emails/*
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ issues:
- .buildkite/*
- .github/*
- docker/*
- test/*
exclude-files: []
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ repos:
hooks:
- id: yamlfmt
- repo: https://github.com/crate-ci/typos
rev: typos-dict-v0.11.27
rev: v1.24.5
hooks:
- id: typos
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,42 @@ import (
)

func main() {
sender := resend.NewResendEmailSender("your_resend_api_token")
msg := newman.NewEmailMessage("no-reply@youremailaddress.com", []string{"mitb@emailsendingfun.com"}, "Isnt sending emails with golang fun?", "Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming")

if err := sender.SendEmail(context.TODO(), *msg); err != nil {
log.Fatal(err)
}
sender, err := resend.New("your_resend_api_token")
if err != nil {
log.Fatal(err)
}

msg := newman.NewEmailMessageWithOptions(
newman.WithFrom("no-reply@youremailaddress.com"),
newman.WithTo([]string{"mitb@emailsendingfun.com"}),
newman.WithSubject("Isn't sending emails with golang fun?"),
newman.WithHTML("<p>Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming</p>"),
)

if err := sender.SendEmail(msg); err != nil {
log.Fatal(err)
}
}
```

This package supports various email providers and can be extended to include more
### Development Mode

To switch to development an just log the email to a file instead of sending an email you can use the `mock` provider. With the `resend` provider, this is made easy with the `WithDevMode` option

```go
sender, err := resend.New("", resend.WithDevMode("emails"))
if err != nil {
log.Fatal(err)
}
```

### Implemented providers
This will put the emails that would be send in the `emails/` directory instead.



## Implemented Providers

This package supports various email providers and can be extended to include more

- Gmail
- SendGrid
Expand Down
13 changes: 7 additions & 6 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ tasks:
aliases: [cover]
cmds:
- go test -v ./... -coverprofile=coverage.out

go:test:coverout:
desc: runs and outputs results of created go tests with coverage
aliases: [cover]
cmds:
- task: go:test:cover
- go tool cover -html=coverage.out

go:fmt:
Expand All @@ -29,19 +35,14 @@ tasks:
cmds:
- go mod tidy

go:build:
desc: Runs go build for the newman server
cmds:
- go build -mod=mod -o newman

go:all:
aliases: [go]
desc: Runs all go test and lint related tasks
cmds:
- task: go:tidy
- task: go:fmt
- task: go:lint
- task: go:test:cover
- task: go:test:coverout

precommit-full:
desc: Lint the project against all files
Expand Down
37 changes: 20 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,54 @@ module github.com/theopenlane/newman
go 1.23.0

require (
github.com/mailgun/mailgun-go/v4 v4.15.0
github.com/microcosm-cc/bluemonday v1.0.27
github.com/resend/resend-go/v2 v2.11.0
github.com/sendgrid/rest v2.6.9+incompatible
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
github.com/stretchr/testify v1.9.0
github.com/theopenlane/httpsling v0.2.0
golang.org/x/oauth2 v0.23.0
google.golang.org/api v0.196.0
)

require (
cloud.google.com/go/auth v0.9.3 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/chi/v5 v5.0.8 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.3 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/theopenlane/echox v0.1.0 // indirect
github.com/theopenlane/utils v0.1.5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/mailgun/mailgun-go/v4 v4.15.0
github.com/resend/resend-go/v2 v2.11.0
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.23.0
google.golang.org/api v0.196.0
)
32 changes: 23 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -52,9 +53,12 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
Expand All @@ -67,20 +71,25 @@ github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDP
github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mailgun/mailgun-go/v4 v4.15.0 h1:3NQU0r2XItJbyIZ21iBI9ps0+vPIMoGyI2XK7ZTN/DQ=
github.com/mailgun/mailgun-go/v4 v4.15.0/go.mod h1:L9s941Lgk7iB3TgywTPz074pK2Ekkg4kgbnAaAyJ2z8=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/resend/resend-go/v2 v2.11.0 h1:Ja5eXizUCbvyLgbiP8sFsJW/UN1b7d6IEUqi80IlgiU=
github.com/resend/resend-go/v2 v2.11.0/go.mod h1:ihnxc7wPpSgans8RV8d8dIF4hYWVsqMK5KxXAr9LIos=
Expand All @@ -97,6 +106,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/theopenlane/echox v0.1.0 h1:y4Z2shaODCLwXHsHBrY/EkH/2sIuo49xdIfxx7h+Zvg=
github.com/theopenlane/echox v0.1.0/go.mod h1:RaynhPvY9qbLOVlcO7Js1NqZ66+CP9hVBa0c7ehNYA4=
github.com/theopenlane/httpsling v0.2.0 h1:5k/PoFA5jjak9dnijATFvTVTvgUSMFdEZeyctyv1cWU=
github.com/theopenlane/httpsling v0.2.0/go.mod h1:Ta/8bjv4JhKT0Xk1hD2Iott9BKLCqXvscmjolSB/bBY=
github.com/theopenlane/utils v0.1.5 h1:4DRieQmsBF87n4lPjEkTt6s4iVRQaCGYlk2+C05lt3o=
github.com/theopenlane/utils v0.1.5/go.mod h1:LWJzG9FfklsLlqWx/VdmfBMuNk700cWqHAwQL0299FM=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
Expand Down Expand Up @@ -154,9 +169,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f h1:b1Ln/PG8orm0SsBbHZWke8dDp2lrCD4jSmfglFpTZbk=
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
27 changes: 21 additions & 6 deletions newman.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package newman

import "github.com/theopenlane/newman/shared"
import (
"context"

"github.com/theopenlane/newman/shared"
)

// EmailSender interface defines the method to send an email
type EmailSender interface {
// SendEmail sends an email with the given message
SendEmail(message *EmailMessage) error
// SendEmailWithContext sends an email with the given message and context
SendEmailWithContext(ctx context.Context, message *EmailMessage) error
}

// EmailMessage represents an email message
Expand All @@ -14,14 +20,23 @@ type EmailMessage = shared.EmailMessage
// Attachment represents an email attachment with its filename and content
type Attachment = shared.Attachment

// Tag is used to define custom metadata for message
type Tag = shared.Tag

// NewEmailMessage creates a new EmailMessage with the required fields
func NewEmailMessage(from string, to []string, subject string, body string) *EmailMessage {
return shared.NewEmailMessage(from, to, subject, body)
}

// NewFullEmailMessage creates a new EmailMessage with all fields
func NewFullEmailMessage(from string, to []string, subject string, cc []string, bcc []string, replyTo string, textBody string, htmlBody string, attachments []*Attachment) *EmailMessage {
return shared.NewFullEmailMessage(from, to, subject, cc, bcc, replyTo, textBody, htmlBody, attachments)
// NewEmailMessageWithOptions creates a new EmailMessage with the specified options.
func NewEmailMessageWithOptions(options ...MessageOption) *EmailMessage {
s := EmailMessage{}

for _, option := range options {
option(&s)
}

return &s
}

// NewAttachment creates a new Attachment instance with the specified filename and content
Expand All @@ -41,12 +56,12 @@ func BuildMimeMessage(message *EmailMessage) ([]byte, error) {

// ValidateEmail validates and sanitizes an email address
func ValidateEmail(email string) string {
return shared.ValidateEmail(email)
return shared.ValidateEmailAddress(email)
}

// ValidateEmailSlice validates and sanitizes a slice of email addresses
func ValidateEmailSlice(emails []string) []string {
return shared.ValidateEmailSlice(emails)
return shared.ValidateEmailAddresses(emails)
}

// GetMimeType returns the MIME type based on the file extension
Expand Down
Loading

0 comments on commit 5131a45

Please sign in to comment.