sendgrid-dev

command module
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: MIT-0 Imports: 3 Imported by: 0

README

SendGrid Mock API

SendGrid Dev is SengGrid mock API for test your sendgrid emails during development.

SengGrid MailDev is Docker container with SendGrid Mock API + MailDev.

Requirements

  • Go 1.21+

Debug

Sample with MailDev (Can work by default)

Run maildev

docker pull maildev/maildev
docker run -p 1080:1080 -p 1025:1025 maildev/maildev

Run SendGrid Mock API

go run main.go

Send mail by curl

curl --request POST \
  --url http://localhost:3030/v3/mail/send \
  --header 'Authorization: Bearer SG.xxxxx' \
  --header 'Content-Type: application/json' \
  --data '{"personalizations": [{ 
    "to": [{"email": "to@example.com"}]}], 
    "from": {"email": "from@example.com"}, 
    "subject": "Test Subject", 
    "content": [{"type": "text/plain", "value": "Test Content"}] 
  }'

Check with maildev

http://localhost:1080/

Sample with MailTrap (with SMTP Auth)

Run SendGrid Mock API

export SENDGRID_DEV_API_SERVER=:3030
export SENDGRID_DEV_API_KEY=SG.xxxxx
export SENDGRID_DEV_SMTP_SERVER=smtp.mailtrap.io:25
export SENDGRID_DEV_SMTP_USERNAME=mailtrap_username
export SENDGRID_DEV_SMTP_PASSWORD=mailtrap_password
go run main.go

Send mail by curl

curl --request POST \
  --url http://localhost:3030/v3/mail/send \
  --header 'Authorization: Bearer SG.xxxxx' \
  --header 'Content-Type: application/json' \
  --data '{"personalizations": [{ 
    "to": [{"email": "to@example.com"}]}], 
    "from": {"email": "from@example.com"}, 
    "subject": "Test Subject", 
    "content": [{"type": "text/plain", "value": "Test Content"}] 
  }'

Check with mailtrap Inbox

https://mailtrap.io/inboxes

Test

go test

Build

x86_64
env GOOS=linux GOARCH=amd64 go build -o sendgrid-dev_x86_64 main.go
arm64
env GOOS=linux GOARCH=arm64 go build -o sendgrid-dev_aarch64 main.go

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL