Notifications client
The Notifications client can be used to manage and send notifications.
The client variable in the following code examples refers to the IMClient instance. When using the Web SDK, the variable name can be chosen freely, but it is also called client at instantiation in the documentation.
Email templates
Email template entities contain the templates for sending emails. The variables can be resolved at runtime.
IMailTemplateEntity is a subtype of IEntity. It provides C# properties and methods for the members on the M.Mailing.Template entity definition.
To get these email templates, the client provides extra getters that are not available on the entities client. It allows fetching email templates by name. However, every operation on an IEntity still applies to IMailTemplateEntity. Saving and deleting IMailTemplateEntity objects is still done through the entities client.
Create an email template
A simple hello world template could look like this:
Send email notifications
Emails can be sent to users by username, user ID, or by a broadcast. There are three respective overloads to the SendEmailNotificationAsync with the following input:
-
MailRequestById- for specifying users by ID. -
MailRequestByUsername- for specifying users by username. -
MailRequestBroadcast- sends to all users.
An email broadcast could be sent using the template:
This would send an e-mail containing "Hello world!", to everyone.
Send real-time notifications
Real-time notifications can be sent to users by username, user ID, or by a broadcast. There are three respective overloads to the SendRealTimeNotificationAsync with the following input:
-
RealtimeRequestById- for specifying users by ID. -
RealtimeRequestByUsername- for specifying users by username. -
RealtimeRequestBroadcast- sends to all users.
Here's an example of a real-time notification sent to the DemoUser:
The link is opened when the user clicks the notification.
This real-time request interface is built on the standard notifications API, which uses an options object that contains all the notification information. This object is directly passed from the IRealtimeRequest.Options property. Some helper methods have been provided to help configure this options object, for example, the body and the icon of the notification.
Send confirmation emails
For SendConfirmationEmailAsync to work, you must set EnableConfirmationMail to true in the settings.
Sending confirmation emails to users can be done using IDs or usernames:
This will send an email to the specified user, containing a secure link to activate their account.