reset password email templates

南笙酒味 提交于 2019-12-13 06:39:33

问题


I have created the helpers and event for forgot the password and also I have written code for contact email and the code is working successfully and am able to send emails but I want to use an email template. I did a verification email used an email template using a package called "meteor add meteorhacks:ssr" from atmosphere as suggested before.

Here is the code which I have written and plz help me out

        Template.recoverPassword.events({ 
            'submit #recovery-form':function(e,t){
                e.preventDefault();
                var email= t.find('#recovery-email').value;
                Accounts.forgotPassword({email: email},function(error){
                    if(error){
                        alert("unable to send reset link");
                    }
                    else{
                        alert("password reset link sent");
                    }
                }); 

I have Written methods for sending email, as below under server side methods.js

 Meteor.methods({

      'sendEmail' :function(from,phone,fname,subj,body){
        this.unblock();
        Email.send({
          to:'sample@sample.com',
          from:from,
          subject:subj,
          text:phone,
          text:fname,
          text:body,
          html: SSR.render('contactbody', sendEmail)
        })
      },

Please suggest to me how to include a email template for both forgot password and contact email. I have tried with ssr package created a email body under private folder and tried to insert on server side but it is not working but and so looking for a help !!! please suggest me how to approach.


回答1:


For sending reset password email

Accounts.emailTemplates.resetPassword.html = function (user, url) {
       SSR.compileTemplate( 'registartionEmail', Assets.getText( 'email_templates/registration_confirm.html' ) );
       var emailData = {
              x: y;
       };
       return SSR.render( 'registartionEmail', emailData );
};

For Sending Contact Mail

Clint Side: You can use any editor to write the mail from user. You can also use some tage like {{username}}, {{date}}... for sending mail to user form admin.

And on submit event you can call the server method.

Meteor.call('sendEmail',
            'admin@example.com',
            Meteor.user().emails[0].address,
            'Hello from Meteor!',
            'This is a test of Email.send.');

Server Side:

You can use SSR if you are using spacbar in your mail body html/text.

Meteor.methods({
  sendEmail: function (to, from, subject, text) {
    check([to, from, subject, text], [String]);
    // Let other method calls from the same client start running,
    // without waiting for the email sending to complete.
    this.unblock();
    Email.send({
      to: to,
      from: from,
      subject: subject,
      text: SSR.render("text", {username: "Pankaj"})
    });
  }
});


来源:https://stackoverflow.com/questions/40085191/reset-password-email-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!