Skip to content

Instantly share code, notes, and snippets.

@thosakwe
Last active February 28, 2020 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thosakwe/99742f181b92ef47ee355e30f02e67d0 to your computer and use it in GitHub Desktop.
Save thosakwe/99742f181b92ef47ee355e30f02e67d0 to your computer and use it in GitHub Desktop.
Angel mailer...

angel_mail

A service for Angel that uses package:mailer to send e-mails. It also supports rendering templates (Jael, mustache, whatever), which makes developing email templates easier. In addition, if given an assetsDir, it will inline CSS stylesheets (use cacheAssets: true in production).

AngelConfigurer configureServer(FileSystem fs) {
return (Angel app) async {
var mailer = Mailer(gmail(...), assetsDir: fs.directory('web/dist'), cacheAssets: true);
app.container.registerSingleton(mailer);
};
}
Future<void> someRoute(RequestContext req, ResponseContext res) async {
var mailer = req.container.make<Mailer>();
// Send email, causes 500 if fails
await mailer.send(to, title, html: '...');
// Send emails, catch errors without crashing
await mailer.trySend(to, title, html: '...');
// Render email-foo.jael (or whatever engine, just uses app.viewGenerator)
await mailer.send(to, title, from: 'a@b.c', view: 'email-foo', locals: {...});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment