Currently, I am working on a Cloud Function within Firebase to integrate with Mailgun for sending emails, following the guidelines provided in the Mailgun documentation.
My challenge lies in implementing this functionality using TypeScript, as I have been unable to locate any examples demonstrating how to configure the API KEY, DOMAIN, and ultimately send the email. Most resources available only show examples in JavaScript.
Here is an example in JavaScript:
var API_KEY = 'YOUR_API_KEY';
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({apiKey: API_KEY, domain: DOMAIN});
const data = {
from: 'Excited User <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04696144776569746861772a6965d686d6c63636b6669692a69686e67616a23686569">[email protected]</a>>',
to: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee888181ae8b968f839e828bc08d81898386878e89898b82">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6705061527021f060a170b024904080a">[email protected]</a>',
subject: 'Hello',
text: 'Testing some Mailgun awesomeness!'
};
mailgun.messages().send(data, (error, body) => {
console.log(body);
});
And here's what it looks like in TypeScript:
const API_KEY = 'YOUR_API_KEY';
const DOMAIN = 'YOUR_DOMAIN_NAME';
import * as mailgun from 'mailgun-js';
// How do I set this up ?
// How can I send the email ?
Although I attempted to use the ts-mailgun package, which simplifies email sending tasks, I encountered issues when deploying the function due to errors.
Ultimately, my objective is to successfully configure Mailgun using TypeScript to effectively deliver emails to users.