How can I send email using an auth0 email Template or trigger an email to be sent from an Action?
My goal is to send an email to the user when he logins if he has not changed his password for a given time. Any other idea of the best way to manage that?
I have written a code snippet below to make an Axios request to the Change Password endpoint. From here, you will need to write the code to compare the user’s last password change to a given time, and if it satisfies, you can call the sendPasswordResetEmail() function.
exports.onExecutePostLogin = async (event, api) => {
var axios = require("axios").default;
const sendPasswordResetEmail = () => {
var options = {
method: 'POST',
url: 'https://YOUR_DOMAIN}/dbconnections/change_password',
headers: {'content-type': 'application/json'},
data: {
client_id: 'event.client.client_id',
email: 'event.user.email',
connection: 'event.connection.name'
}
};
try{
axios.request(options).then(function (response) {
console.log("Response: ",response.data);
})
}catch(error){
console.error(error)
}
}
/*
Check if the user has not changed their password for a given time.
If this is true, call the sendPasswordResetEmail() function.
*/
}