sendgrid-pit serves as an emulator of Twilio's SendGrid service.
782
mailpit for sendgrid
sendgrid-pit serves as an emulator of Twilio's SendGrid service.
Get the image from docker hub
docker pull pointw/sendgrid-pit
Use the included docker-compose.yml file to spin up sendgrid-pit and mongo, or use this to copy into your own docker-compose.yml file.
Alternately (minimal and ephemeral)
docker run -d --rm --name sendgrid-pit -p 8825:8825 pointw/sendgrid-pit
Here is a simple Typescript that connects the emulator instead of the real SendGrid service:
import sendGridClient from '@sendgrid/mail';
import client from '@sendgrid/client';
import { MailDataRequired } from '@sendgrid/mail'
const useEmulator = true;
const apiKey = useEmulator? 'SG.mock-sendgrid' : 'SG.real-api-key'
export async function sendEmail() {
client.setApiKey(apiKey);
if (useEmulator) {
client.setDefaultRequest('baseUrl', 'http://localhost:8825');
}
sendGridClient.setClient(client);
const body = 'Message for you, sir!';
const message: MailDataRequired = {
to: '[email protected]',
from: '[email protected]',
replyTo: '[email protected]',
content: [
{type: 'text/plain', value: body}
]
};
const [response, _] = await sendGridClient.send(message);
return response
}
POST /v3/mail/send (the sendgrid client uses this endpoint)The UI uses these endpoints. You may find use for them too.
Retrieve sent messages: GET /api/messages
[email protected] returns only messages where that address appears in any recipient field (To/CC/BCC), including inside personalizations[].to/cc/bcc.Delete sent mail(s): DELETE /api/messages/{messageId}
DELETE /api/messages clears all messages.DELETE /api/[email protected] deletes only messages where that address is a recipient (To/CC/BCC, including personalizations).Mark mails as read:
PATCH /api/messages/{messageId} (read field only allowed)POST /api/messages/mark-all-readEvent stream (SSE): /events
GET /api/templatesPOST /api/templates (body: { title: string, templateId: string, subject?: string, templateBody?: string, testData?: string })PATCH /api/templates/{id} (any of: title, templateId, subject, templateBody, testData)DELETE /api/templates/{id}Templatized subjects
subject string that supports Handlebars (same data as the body).template_id) and includes personalizations[n].dynamic_template_data, the subject displayed is the rendered template subject; otherwise the message’s subject is shown.PORT environment variable)Use the interactive CLI in scripts/tui to send messages via real SendGrid or this emulator.
cd scripts/tui && npm i && npm run buildnode dist/cli.js (prompts for missing values)node dist/cli.js --provider pit --base-url http://localhost:8825 --from [email protected] --to [email protected] --subject "Hi" --text "Hello"node dist/cli.js --provider sendgrid --api-key $SENDGRID_API_KEY --from [email protected] --to [email protected] --template-id d-...Answers and defaults
sg-sender.answers.json (change with --answers-file path.json).--defaults uses saved values without prompting; otherwise prompts but pre‑fills from the answers file.sendgrid, API key is masked and not saved; for pit, API key is optional and saved if provided.Editing HTML/JSON
$VISUAL/$EDITOR (falls back to nano or notepad). Save and close to continue.See scripts/tui/README.md for full CLI options and examples.
8825) the port the emulator listens on (both api and ui)sendgrid-pit) - the MongoDB database name
messages and templatesContent type
Image
Digest
sha256:3f6d5a20a…
Size
155.1 MB
Last updated
2 days ago
docker pull pointw/sendgrid-pit