SendGrid transport for the Upyo email library.
npm add @upyo/core @upyo/sendgrid
pnpm add @upyo/core @upyo/sendgrid
yarn add @upyo/core @upyo/sendgrid
deno add --jsr @upyo/core @upyo/sendgrid
bun add @upyo/core @upyo/sendgridimport { createMessage } from "@upyo/core";
import { SendGridTransport } from "@upyo/sendgrid";
import fs from "node:fs/promises";
import process from "node:process";
const message = createMessage({
from: "sender@example.com",
to: "recipient@example.net",
subject: "Hello from Upyo!",
content: { text: "This is a test email." },
attachments: [
new File(
[await fs.readFile("image.jpg"), "image.jpg", { type: "image/jpeg" }]
)
],
});
const transport = new SendGridTransport({
apiKey: process.env.SENDGRID_API_KEY!,
});
const receipt = await transport.send(message);
if (receipt.successful) {
console.log("Message sent with ID:", receipt.messageId);
} else {
console.error("Send failed:", receipt.errorMessages.join(", "));
}See the SendGrid docs for more information about configuration options.
apiKey: Your SendGrid API key (starts withSG.)baseUrl: SendGrid API base URL (default:https://api.sendgrid.com/v3)timeout: Request timeout in milliseconds (default: 30000)retries: Number of retry attempts (default: 3)clickTracking: Enable click tracking (default: true)openTracking: Enable open tracking (default: true)subscriptionTracking: Enable subscription tracking (default: false)googleAnalytics: Enable Google Analytics tracking (default: false)