- Resend
- SendGrid
To send an email using Resend, use the
resend SDK. Set your Resend API key as an environment secret named RESEND_API_KEY.Copy
import * as BunnySDK from "@bunny.net/edgescript-sdk";
import { Resend } from "https://esm.sh/resend";
import process from "node:process";
const resend = new Resend(process.env.RESEND_API_KEY);
BunnySDK.net.http.serve(async (req) => {
try {
await resend.emails.send({
from: "[email protected]",
to: "[email protected]",
subject: "Welcome to Bunny Edge Scripting!",
text: "This email was sent directly from the edge.",
});
return new Response("Email sent successfully!");
} catch (error) {
console.error(error);
return new Response("Failed to send email.", { status: 500 });
}
});
To send an email using SendGrid, use the
@sendgrid/mail SDK. Set your SendGrid API key as an environment secret named SENDGRID_API_KEY.Copy
import * as BunnySDK from "@bunny.net/edgescript-sdk";
import sgMail from "https://esm.sh/@sendgrid/[email protected]";
import process from "node:process";
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
BunnySDK.net.http.serve(async (req) => {
const msg = {
to: "[email protected]",
from: "[email protected]",
subject: "Welcome to Bunny Edge Scripting!",
text: "This email was sent directly from the edge.",
};
try {
await sgMail.send(msg);
return new Response("Email sent successfully!");
} catch (error) {
console.error(error);
return new Response("Failed to send email.", { status: 500 });
}
});