Integrate Lovable with Mailgun using our concise, step-by-step guide. Unlock configuration tips, troubleshooting advice, and best practices for email deliverability.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
export interface MailgunConfig {
apiKey: string;
domain: string;
}
export interface EmailData {
from: string;
to: string;
subject: string;
text: string;
}
export async function sendEmail(
config: MailgunConfig,
emailData: EmailData
): Promise {
const url = https://api.mailgun.net/v3/${config.domain}/messages;
const formData = new URLSearchParams();
formData.append("from", emailData.from);
formData.append("to", emailData.to);
formData.append("subject", emailData.subject);
formData.append("text", emailData.text);
// btoa is used to Base64 encode the API key for Mailgun authentication
const auth = btoa(api:${config.apiKey});
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": Basic ${auth},
"Content-Type": "application/x-www-form-urlencoded"
},
body: formData.toString()
});
return response.json();
}
import { sendEmail, MailgunConfig, EmailData } from "./mailgunService";
// Replace the placeholders with your actual Mailgun credentials
const mailgunConfig: MailgunConfig = {
apiKey: "YOURMAILGUNAPI_KEY",
domain: "YOURMAILGUNDOMAIN" // e.g. "sandbox123.mailgun.org"
};
const emailData: EmailData = {
from: "Excited User <mailgun@YOURMAILGUNDOMAIN>",
to: "[email protected]",
subject: "Hello from Lovable Project",
text: "Testing some Mailgun awesomeness with our Lovable project!"
};
// Call the sendEmail function when needed in your project
sendEmail(mailgunConfig, emailData)
.then(response => {
console.log("Email sent successfully:", response);
})
.catch(error => {
console.error("Error sending email:", error);
});
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.