AuthAlert integrates with Mailgun to send authentication alerts. This integration allows you to connect AuthAlert with Mailgun and use a Mailgun template to send customized authentication alerts without coding.
To send emails using Mailgun, first add and verify your domain in your Mailgun account. Once your domain is ready for sending emails, navigate to Domain settings → Sending API keys to create a new API key. Be sure to save this key for later use.
You'll need a template to format the alert emails. To create one, go to Templates and click Create message template. Mailgun provides a drag-and-drop visual editor for this purpose. The AuthAlert integration offers the following variables to help personalize your alert emails:
Here's an example template in Mailgun:
After setting up Mailgun, go to the AuthAlert project settings interface. Toggle on the Mailgun Notification Integration and fill in these details:
Save these settings to activate the integration.
After enabling the Mailgun integration, call the API like this:
import AuthAlertAPI from 'authalert';
const projectId = "your_project_ID";
const result = await AuthAlertAPI(projectId, {
user_id: user.id,
email: user.email,
first_name: user.first_name,
last_name: user.last_name
});
console.log(result);
To use the Mailgun integration, you must provide a valid email for the user so that alert emails can be sent. Both first_name and last_name are optional but helpful for personalizing the message.
Learn more about how to boost your application security in software development