LogoLogo
  • Introduction
  • What's New?
  • Upgrade Guide
  • Getting Started
    • Requirements
    • Installation
  • Defining Channels
    • Configuration
    • Retrieving Channels
  • Creating and Sending Notifications
    • Defining Notifications
    • Notifiables
    • Sending Notifications
  • Providers
    • DatabaseProvider
    • EmailProvider
    • SlackProvider
      • Slack BlockKit
    • Creating Custom Providers
  • Testing
    • Coming Soon
  • Reference
    • NotificationService
    • BaseNotification
    • SendsNotifications
    • INotifiable
    • BaseProvider
      • DatabaseProvider
        • DatabaseNotificationService
        • HasDatabaseNotifications
        • DatabaseNotificationCursor
        • DatabaseNotification
      • EmailProvider
      • SlackProvider
        • SlackMessage
          • EventMetadata
          • ActionsBlock
          • ContextBlock
          • DividerBlock
          • HeaderBlock
          • ImageBlock
          • SectionBlock
          • ButtonElement
          • ConfirmObject
          • ImageElement
          • TextObject
          • PlainTextOnlyTextObject
  • ForgeBox
  • GitHub
Powered by GitBook
On this page
  • Requirements
  • Configuration
  • toEmail
  • routeNotificationForEmail
  1. Providers

EmailProvider

PreviousDatabaseProviderNextSlackProvider

Last updated 1 year ago

The EmailProvider sends notifications using .

Requirements

To use the EmailProvider, you need installed. This is not installed by Megaphone. If you do not have installed, an exception will be thrown if you try to define a channel with the EmailProvider.

Configuration

The EmailProvider accepts the following properties:

{
    "mailer": "default", // optional, uses the cbMailServices default otherwise
    "onSuccess": () => {}, // optional, logs to info otherwise
    "onFailure": () => {} // optional, logs to error otherwise
}

toEmail

The toEmail method returns a Mail@cbmailservices instance to send. The to property can be either defined in the toEmail method or a routeNotificationForEmail method defined on the Notifiable instance.

public struct function toEmail( notifiable, newMail ) {
    return newMail(
        to = notifiable.getEmail(),
        from = "noreply@example.com",
        subject = "Megaphone Email Notification",
        type = "html",
        bodyTokens = { product: "ColdBox" }
    ).setBody( "
        <p>Thank you for downloading @product@, have a great day!</p>
    " );
}

routeNotificationForEmail

You can let the Notifiable instance define how to send the Email Notification by adding a routeNotificationForEmail method.

component accessors="true" {
    
    property name="email";
    
    public string function routeNotificationForEmail() {
        return getEmail();
    }

}
cbMailServices
cbMailServices
cbMailServices