Search the site
BACKEND
Send email, in-app and push notifications through DV.Notifications.
Mail is part of it, at DV.Notifications.mail.
ON THIS PAGE
Pick a mail provider
Send an email
Notify a person on several channels
Status
void configureMail() {
DV.Notifications.mail.useProvider(SmtpMailProvider(
host: 'smtp.example.com',
username: 'apikey',
password: DV.Secrets.get('SMTP_PASSWORD'),
));
}Copy code to clipboard
SmtpMailProvider
Sends through: Any SMTP server, port 587 by default
ResendMailProvider
Sends through: Resend
SendGridMailProvider
Sends through: SendGrid
PostmarkMailProvider
Sends through: Postmark
SesMailProvider
Sends through: Amazon SES
MailgunMailProvider
Sends through: Mailgun
DVMemoryMailProvider
Sends through: Nowhere. It keeps messages in .sent for tests
Providers are set in code. Read passwords and API keys with DV.Secrets.get.
await DV.Notifications.mail.send(const DVMailMessage(
from: DVMailAddress('hello@example.com', name: 'Shop'),
to: <DVMailAddress>[DVMailAddress('ada@example.com')],
subject: 'Your order shipped',
text: 'It arrives on Friday.',
));Copy code to clipboard
Add html: for an HTML body next to the text one.
send throws when no mail provider is set.
DV.Notifications.register(DVMemoryNotificationProvider());
final DVNotificationDelivery delivery = await DV.Notifications.send(
'user-1',
const DVNotificationMessage(
title: 'Order shipped',
body: 'It arrives on Friday.',
channels: <DVNotificationChannel>[DVNotificationChannel.inApp],
),
);Copy code to clipboard
Channels are inApp, email, push, sms and webPush.
Register one provider per kind, such as FirebasePushProvider, ApnsPushProvider, WebPushProvider or TwilioSmsProvider.
useRoutes tells the service each person's address and device tokens.
push tries the native providers first and falls back to Web Push when none is registered or the one that is fails.
usePreferences reads each person's muted channels and quiet hours. Push, web push and SMS are not sent during quiet hours, and email is.
send returns a DVNotificationDelivery with the outcome of every channel, so a muted or unrouted channel is told apart from one that failed.
Partial
Spec section: Mail and Notifications
Planned work and implementation limits
No attachments, bounce webhooks or List-Unsubscribe header.
Mail is sent directly, and not through the job queue.
Desktop and TV push kinds have no implementation.
FSL-1.1-MIT licensed. Built with Dartvel.
Dartvel is made by
To the bottom