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).
Last active
February 28, 2020 00:10
-
-
Save thosakwe/99742f181b92ef47ee355e30f02e67d0 to your computer and use it in GitHub Desktop.
Angel mailer...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AngelConfigurer configureServer(FileSystem fs) { | |
return (Angel app) async { | |
var mailer = Mailer(gmail(...), assetsDir: fs.directory('web/dist'), cacheAssets: true); | |
app.container.registerSingleton(mailer); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', view: 'email-foo', locals: {...}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment