Reputation: 7362
I am looking to use a sendgrid template to send the account password reset email.
So basically instead of using the function Accounts.sendResetPasswordEmail
I need the function Accounts.getResetPasswordURL
Which will give me a password reset URL which I can use to send over to sendgrid which will be used in a template.
So how can I do this? How can I use Meteor to just get the password reset URL but not actually send the email? I will send the email with the URL manually using a API call to sendgrid.
Upvotes: 2
Views: 1000
Reputation: 4091
Note: I haven't used sendgrid, so I'm going by the API over here.
First off, you want to configure Meteor to use Sendgrid's SMTP servers. This way, you can send e-mails straight through Meteor:
Meteor.startup(function(){
process.env.MAIL_URL = "smtp://" + sendgridUsername + ":" + sendgridPasswordOrAPIkey + "@smtp.sendgrid.net:465";
});
You can change the default template for the reset e-mail. This can be done by modifying Accounts.emailTemplates
:
Accounts.emailTemplates.resetPassword.html = function(user, url){
// url contains the reset url! :)
var result;
var sendgridTemplateId = ''; // Set this to the template id you're using in sendgrid
try {
// Get sendgrid template
// API link: https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/templates.html
result = HTTP.get("https://api.sendgrid.com/v3/templates/" + sendgridTemplateId);
result = result.data.templates[0].versions[0].html_content;
// then insert URL to the template
} catch (error) {
console.error('Error while fetching sendgrid template!', error);
return false;
}
return result;
};
Now when you use Accounts.sendResetPasswordEmail()
the above template will be used, which actually just fetches the sendgrid template and returns that!
Upvotes: 1
Reputation: 16478
This is not really possible with the way the procedure is performed at the moment.
The accounts-password
package generates a random token and sends the email in the sendResetPasswordEmail()
method.
You can either fork the package, generate your own token the way it is done in the original method, or change the behavior of the email package to handle email on your own.
Upvotes: 0