Switch branches/tags
test-tag release-513.003 release-513.002 release-513.001 release-512.002 release-512.001 release-511.003 release-511.002 release-511.001 release-510.002 release-510.001 release-509.004 release-509.003 release-509.002 release-509.001 release-508.001 release-507.002 release-507.001 release-506.001 release-505.008 release-505.007 release-505.006 release-505.005 release-505.004 release-505.003 release-505.002 release-505.001 release-504.004 release-504.003 release-504.002 release-504.001 release-503.003 release-503.002 release-503.001 release-502.001 release-501.002 release-501.001 release-500.002 release-500.001 release-499.005 release-499.004 release-499.003 release-499.002 release-499.001 release-498.003 release-498.002 release-498.001 release-497.002 release-497.001 release-496.006 release-496.005 release-496.004 release-496.003 release-496.002 release-496.001 release-495.005 release-495.004 release-495.003 release-495.002 release-495.001 release-494.003 release-494.002 release-494.001 release-493.004 release-493.003 release-493.002 release-493.001 release-492.003 release-492.002 release-492.001 release-491.003 release-491.002 release-491.001 release-490.002 release-490.001 release-489.005 release-489.004 release-489.003 release-489.002 release-489.001 release-488.006 release-488.005 release-488.004 release-488.003 release-488.002 release-488.001 release-487.002 release-487.001 release-486.001 release-485.006 release-485.005 release-485.004 release-485.003 release-485.002 release-485.001 release-484.004 release-484.003 release-484.002 release-484.001 release-483.005
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
Controller
i18n
styles
templates
tests
Email.i18n.php
Email.setup.php
EmailController.class.php
EmailExceptions.class.php
EmailHelper.class.php
EmailImageHelper.class.php
EmailMobileBadges.class.php
MobileApplicationsLinksGenerator.class.php
README.md
SocialLinksGenerator.class.php
SpecialSendEmailController.class.php
crowdin.conf

README.md

Email Framework

This extension allows emails to be constructed using standard Wikia headers and footers

Testing an Email

Special:SendEmail

Special:SendEmail (e.g. http://garth.wikia.com/wiki/Special:SendEmail) is a special page which presents a list of forms you can use to send off any of our emails. You must be logged in with a staff account to access the page, and each form contains fields which correspond to the required parameters for each of the emails.

Testing Email Via an HTTP Request

In addition to sending an email through Special:SendEmail, you can also send an email by making a request to wikia.php. To test an email you must know:

  • The name of the email controller
  • What parameters that email requires
  • Be logged in as a staff user

To find the controller name, look in the Controller folder and find the file defining the email you'd like to test. For example the Email\Controller\ForgotPasswordController class (in the UserLogin.class.php file) handles the password reset email. The 'Controller' suffix of this name can be left off when calling this controller, so just Email\Controller\ForgotPassword

The parameters required by the email should be listed in the class documentation just above the class definition. For example the ForgotPassword email requires a username parameter. FYI, for this framework, the method is always handle

Finally, you need to be logged in under a staff member account otherwise you will not be able to access this controller for security reasons.

For the ForgotPassword email, the URL is then:

http://garth.garth.wikia-dev.com/wikia.php?controller=Email\Controller\ForgotPassword&method=handle&username=GarthTest400

Adding New Emails

Create a New Controller

First add a new class file in the Controller directory for the feature responsible for this email or use an existing file if that feature already has some emails defined in this framework. There can be multiple classes per file, one per email for that feature.

These classes should inherit from Email\EmailController. The methods this controller can override/implement are:

  • assertCanAccessController : This determines who can access this controller. The defaults, staff and internal requests should be sufficient for almost all cases.
  • assertCanEmail : Determines whether the email should be sent given current business logic.
  • initEmail : Any initialization should be done here. This includes error checking and/or loading request values.
  • getToAddress : Supplies the To address. Default is current user.
  • getFromAddress : Supplies the From address. Defaults to $wgPasswordSender and $wgPasswordSenderName
  • getReplyToAddress : Supplies the Reply-To address. Defaults to $wgNoReplyAddress
  • getSubject : [REQUIRED] Supplies the subject for the email. There is no default.
  • body : A controller method that builds the email body via the view.

Creating a New Template

When defining the body method in the controller, give the template name via the @template annotation. This gives the name of the template, minus the directory and templating suffix.

The main.mustache template is the main layout for all emails and includes the header and footer.

Images

To add a new image, upload it to the WikiaNewsletter wiki and put it in the "Html_Emails" category so we can keep track of all the images used in emails. We'll generate those images dynamically with https://wikia-inc.atlassian.net/browse/SOC-622 but in the mean time the URLs are hard-coded in the templates.

Note that email client support for SVGs is not great, so be sure to use JPG, GIF, or PNG files.

CSS

We're not using SCSS for the HTML emails, although we could theoretically add support for that in the future. For now, we're using plain CSS and CssToInlineStyles for inlining CSS into the templates.

There's one common.css that gets included in every template automatically. For template-specific styles, add them via \Email\EmailController::inlineStyles in the child class' getContent method.

See campaignmonitor.com's cheat sheet for understanding which css properties are supported in major email clients.

Tools

CssToInlineStyles

CssToInlineStyles is a PHP library that will inline CSS properties into the style attribute. It's installed via Composer and can be found in /lib/composer/tijsverkoyen/.