lookback / meteor-emails

Improved Meteor emails with templating, previews and automated CSS/SCSS inlining.

Home Page:https://atmospherejs.com/lookback/emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use to send beautiful "useraccounts"-emails?

thebarty opened this issue · comments

Hi guys,

is there anyone using this package to send "useraccounts"-related emails? Just like https://github.com/yogiben/meteor-pretty-email does, but keeping it consistent?

If yes: Do you mind sharing some code on how you did it?

@johanbrook : How are you doing it? Do you use this package or yogiben? :-)

The built in Meteor email hooks for the Accounts package can accept HTML and plain text (can't find the docs at the moment though), so you can use this package to render the HTML from an email template, and let Meteor send it.

Hi guys,

this is simple stuff, but it might safe you some time if you want to do this yourself.
So this is something for the WIKI of this package:

import { htmlToText } from 'meteor/lookback:html-to-text'

// Enrollment
Accounts.emailTemplates.enrollAccount.from = function () {
  return 'Webmaster <webmaster@noreply.com>'
}
Accounts.emailTemplates.enrollAccount.subject = function () {
  return 'Your subject'
}
Accounts.emailTemplates.enrollAccount.text = function (user, url) {
  const html = Mailer.render('useraccountsEnrollment', {  // email template using `lookback:emails`
    user,
    url,
  })
  return htmlToText.fromString(html)  // CONVERT to text
}
Accounts.emailTemplates.enrollAccount.html = function (user, url) {
  return Mailer.render('useraccountsEnrollment', {  // email template using `lookback:emails`
    user,
    url,
  })
}

// do the same thing with the other email-types (verifyEmail, resetPassword) 
//  you find in the Meteor-docs at http://docs.meteor.com/api/passwords.html#Accounts-emailTemplates