Quick setup examples
RedwoodJS
Send your first email from a RedwoodJS serverless function using the sendping SDK.
Send your first email from a RedwoodJS app using the sendping Node SDK. Install it with npm install sendping, then import SendPing and call mb.emails.send(). Redwood serverless functions live in the api side, so the call (and your key) stay on the server.
Prerequisites
- A SendPing API key.
- A verified domain to send from.
1. Install the SDK
yarn workspace api add sendping2. Add your API key
Add your key to the project .env. Redwood loads it into the api side automatically.
.env
SENDPING_API_KEY=mb_xxxxxxxxx3. Generate a function
Scaffold a serverless function on the api side.
yarn rw g function send4. Send email from the function
Edit the generated handler to use the SDK.
api/src/functions/send/send.ts
import type { APIGatewayEvent, Context } from 'aws-lambda';
import { SendPing } from 'sendping';
const mb = new SendPing(process.env.SENDPING_API_KEY!);
export const handler = async (_event: APIGatewayEvent, _context: Context) => {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@test.sendping.co'],
subject: 'hello world',
html: '<strong>it works!</strong>',
});
return {
statusCode: error ? 500 : 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(error ? { error } : { data }),
};
};A successful call returns the created email's
id. See the full request body in the Send an email reference.