Skip to content

Instantly share code, notes, and snippets.

@locohost
Created June 7, 2025 20:31
Show Gist options
  • Save locohost/693f8afd8db406ede59aa231dfd1714d to your computer and use it in GitHub Desktop.
Save locohost/693f8afd8db406ede59aa231dfd1714d to your computer and use it in GitHub Desktop.
export async function sendMGEmail(to: string, subject: string, text: string, context: ActionAPIContext) {
const { MAILGUN_API_KEY, MAILGUN_SEND_KEY, MAILGUN_DOMAIN, MAILGUN_FROM } = context.locals.runtime.env;
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: "api", //MAILGUN_SEND_KEY as string,
key: MAILGUN_API_KEY as string,
//url: `https://api.mailgun.net`, // MAILGUN_API_URL as string,
});
console.log(`${where}: MAILGUN_API_KEY:`, MAILGUN_API_KEY);
console.log(`${where}: MAILGUN_DOMAIN:`, MAILGUN_DOMAIN);
//console.log(`${where}: mailgun.client:`, mg);
try {
const mgData = await mg.messages.create(`${MAILGUN_DOMAIN}`, {
from: 'Mark <postmaster@mg.myneighborsand.me>', // `${MAILGUN_FROM}>`,
to: [to],
subject,
text,
html: text,
});
return {};
} catch (error) {
debugger;
return { error: `Failed to send email to '${to}': ${error}` };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment