District Core Developer DocsDistrict Core Developer Docs
Developers
Boilerplate
Modules
Bitbucket
Developers
Boilerplate
Modules
Bitbucket
  • Modules

    • ABN
    • ActivityLog
    • AnalyticsApi
    • ApiConnector
    • BlockApi
    • CategoryApi
    • CloneApi
    • CommentApi
    • ContentApi
    • Core
    • Documents
    • EmbedApi
    • Event
    • ExportApi
    • FeatureApi
    • FormApi
    • GTM
    • GalleryApi
    • HelpApi
    • Hotspot
    • IdeaSurvey
    • ImportApi
    • InteractionsApi
    • Intercom
    • MailApi
    • MapApi
    • MapSurvey
    • MediaApi
    • MenuApi
    • MetaTagApi
    • NlpApi
    • NotificationApi
    • Page
    • ParentableContent
    • PaymentApi
    • PermissionsApi
    • Postcode
    • ReCaptcha
    • Redirects
    • Renderer
    • ReportApi
    • RestrictionApi
    • RevisionApi
    • SearchApi
    • Settings
    • ShareableApi
    • Slack
    • SlugApi
    • SubscribableApi
    • Survey
    • Team
    • TenantApi
    • TestApi
    • ThemeApi
    • Timeline
    • TranslationApi
    • Update
    • Users
    • VisualisationApi
    • WorkflowApi
    • Wysiwyg

MailAPI Module

This module handles anything slightly custom regarding sending emails

Services

SMTP

Defaults are setup for lagoon mx which is a cluster internal mail relay. It should never be used for production as may get blacklisted at any time.

Postmark

To use postmark, start with environment variables like this

# For sending mail.
MAIL_MAILER=smtp
MAIL_FROM_ADDRESS=noreply@districtcms.com
MAIL_FROM_NAME="DistrictCMS"
MAIL_HOST=smtp.postmarkapp.com
MAIL_BROADCAST_HOST=smtp-broadcasts.postmarkapp.com
MAIL_USERNAME=postmark-api-key
MAIL_PASSWORD=postmark-api-secret-key
MAIL_ENCRYPTION=tls
MAIL_PORT=587

# For interacting with API.
POSTMARK_TOKEN=postmark-api-token

Transactional emails (forgot password, email verification, etc)

This is the default if above environment variables are used.

Broadcast emails (notifications, bulk sending, etc)

Broadcast emails need to add an additional header to the message, this is done automatically if you use BroadcastMailMessage::new()

return BroadcastMailMessage::new()
    ->subject('My subject')
    ->line('Content');

To tag a message, so it can be filtered in postmark, use PostmarkService::addTagHeader($message, $mailerTag) eg:

return BroadcastMailMessage::new()
  ->withSymfonyMessage(function($message) {
    PostmarkService::addTagHeader($message, 'my unique tag 123');
  });

Validators

No Fake email

To prevent people using fake/temporary emails, this module provides a no_fake_email validator. It will look up against a list provided by wesbos/burner-email-providers. If the email domain is in the list it will fail validation.

Validator::make(['email' => 'email@example.com'], [
  'email' => 'no_fake_email'
])->validate();

Email domain validator

This checks if an email is in a list of domains and only pass if it is. There is no macro for this validator as it requires an array of domains.

Validator::make(['email' => 'email@example.com'], [
  'email' => \Modules\MailApi\Rules\EmailDomain::domains(['gmail.com', 'doghouse.agency'])
])->validate();

Edit this page
Prev
Intercom
Next
MapApi