-
Notifications
You must be signed in to change notification settings - Fork 235
Email Configuration
For certain operations in MembershipReboot, it is necessary to send emails for the operation to be successful. It is expected that the hosting application makes an SMTP server available for use.
In order to support email notifications, a few things need to be configured. First, email notifications are handled as part of the MembershipReboot eventing system. As operations occur on the UserAccount, an event is raised to indicate the operation. This is how the email notifications are implemented -- they handle certain events and send the email as their event processing.
This means the email event handler (called EmailAccountEventsHandler) needs to be registered. This registration is performed on the MembershipRebootConfiguration class via the AddEventHandler API. To send emails it uses the SMTP configuration from the configuration file:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.gmail.com" userName="[email protected]" password="" port="587" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
When sending emails, the EmailAccountEventsHandler needs the text that will be contained in the email. By default this is provided by the EmailMessageFormatter class. It reads templated text files that are embedded within the MembershipReboot assembly itself. This is customizable by either deriving from EmailMessageFormatter or defining a new class that implements IMessageFormatter.
When sending emails, the EmailMessageFormatter needs to embed URLs back into the application (e.g. login, confirm account registration, etc). These endpoints are expected to be implemented by the application itself. To inform the EmailMessageFormatter of the URLs, the AspNetApplicationInformation class can be used. It allows indicating relative paths for the various URLs. If more customization is required, the base ApplicationInformation class can be used instead.
Below is an example of creating all of these objects together:
var config = new MembershipRebootConfiguration();
var appinfo = new AspNetApplicationInformation("Test", "Test Email Signature",
"UserAccount/Login",
"UserAccount/ChangeEmail/Confirm/",
"UserAccount/Register/Cancel/",
"UserAccount/PasswordReset/Confirm/");
var emailFormatter = new EmailMessageFormatter(appinfo);
config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));
Then you can register it
kernel.Bind<MembershipRebootConfiguration>().ToConstant(config)