Mailer for A2

40 views
Skip to first unread message

Tom Boutell

unread,
Nov 16, 2013, 8:06:14 PM11/16/13
to apostr...@googlegroups.com
Sending email is a pretty common operation, and it doesn't make sense
to duplicate that code.

The apostrophe-site module now provides an email transport via the
excellent nodemailer module.

It is available as site.mailer in app.js, and it is passed as the
"mailer" option to every module you configure in app.js.

For docs on usage, just check out nodemailer. (You do not have to
configure a transport - apostrophe-site passes you one; it makes sense
to share a transport object.)

* * *

On a related subject, you can now call self.render in a module with an
explicit file extension. This allows nunjucks to be used conveniently
to generate plaintext emails, as well as HTML emails.

This is available in modules subclassed derived from
apostrophe-snippets, and any other module that uses the assets mixin
(see assets.js in the apostrophe module).

And you can call self.renderPage as well. self.renderPage is only
meant for corner cases like login and password reset pages, little
interactions that need decoration with the outerLayout but have
nothing to do with Apostrophe's page tree at all. But it's super handy
for that situation:

return res.send(self.renderPage('reset', { message: 'whatever' }, 'anon'));

The "anon" argument means "nobody's logged in yet, so don't load the
stuff for logged-in users in the browser."

--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

Mark Janiczak

unread,
Dec 11, 2016, 8:55:01 PM12/11/16
to apostrophenow
Hi Tom,

I have used nodemailer before but I'm having a little trouble accessing the mailer in my module. Could you elaborate on how to access the mailer from a module?

Tom Boutell

unread,
Dec 11, 2016, 9:10:11 PM12/11/16
to apostr...@googlegroups.com
Hi Mark,

We have deprecated this group for new posts, please ask how-to
questions on stackoverflow and tag them "apostrophe-cms". It's the
best way to make sure everyone can find the answers.

(FYI, nothing stops you from just using nodemailer in your module...
which, in Apostrophe 2.x, is currenly the only way to go. In 1.x we
had the emailMixin. Something like it will likely come back.)
> --
> You received this message because you are subscribed to the Google Groups
> "apostrophenow" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to apostropheno...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com

Tom Boutell

unread,
Dec 11, 2016, 9:10:19 PM12/11/16
to apostr...@googlegroups.com
(I should say in 0.5.x.)
Reply all
Reply to author
Forward
0 new messages