LeKoala\EmailTemplates\Email\BetterEmail
An improved and more pleasant base Email class to use on your project
This class is fully decoupled from the EmailTemplate class and keep be used
independantly
Improvements are:
- URL safe rewriting
- Configurable base template (base system use Email class with setHTMLTemplate to provide content)
- Send email according to member locale
- Check for subject
- Send to member or admin
- Persist emails
- Parse body (multi part body is supported)
- Plaintext takes template into account
- Disable emails
- Unified send methods that support hooks
- Author: lekoala
Synopsis
class BetterEmail
extends Email
{
- // constants
- const STATE_CANCELLED = 'cancelled';
- const STATE_NOT_SENT = 'not_sent';
- const STATE_SENT = 'sent';
- const STATE_FAILED = 'failed';
- // members
- protected EmailTemplate $emailTemplate;
- protected $locale;
- protected Member $to_member;
- protected Member $from_member;
- protected boolean $disabled = false;
- protected SentMail $sentMail = NULL;
- protected boolean $sendingCancelled = false;
- // methods
- public void __construct()
- protected SentEmail persist()
- public string getRenderedBody()
- public $this addBody()
- public $this setBody()
- public $this setData()
- public bool send()
- public bool sendPlain()
- public bool doSend()
- public string getSendStatus()
- public bool getSendingCancelled()
- public SentMail getSentMail()
- public $this generatePlainPartFromBody()
- public $this clearBody()
- public $this setHTMLTemplate()
- public static string makeTemplateCode()
- public string renderWithData()
- public $this render()
- public string getLocale()
- public void setLocale()
- public boolean getDisabled()
- public $this setDisabled()
- public Member getToMember()
- public $this setTo()
- public $this setSubject()
- public Email setToAdmin()
- public Email setToContact()
- public Email bccToAdmin()
- public Email bccToContact()
- public BetterEmail setToMember()
- public Member getFromMember()
- public BetterEmail setFromMember()
- public $this setFrom()
- protected static string safeAbsoluteURL()
- protected static void rewriteURLs()
- public EmailTemplate getEmailTemplate()
- public $this setEmailTemplate()
Hierarchy
Extends
- SilverStripe\Control\Email\Email
Tasks
Line | Task |
---|---|
137 | migrate this to a cron task |
Constants
Name | Value |
---|---|
STATE_CANCELLED | 'cancelled' |
STATE_NOT_SENT | 'not_sent' |
STATE_SENT | 'sent' |
STATE_FAILED | 'failed' |
Members
protected
- $disabled — boolean
- $emailTemplate — LeKoala\EmailTemplates\Models\EmailTemplate
- $from_member — SilverStripe\Security\Member
- $locale — string
- $sendingCancelled — boolean
- $sentMail — LeKoala\EmailTemplates\Email\SentMail
- $to_member — SilverStripe\Security\Member
Methods
protected
- persist() — Persists the email to the database
- rewriteURLs() — Turn all relative URLs in the content to absolute URLs
- safeAbsoluteURL() — Bug safe absolute url that support subsites
public
- __construct() — Email constructor.
- addBody() — Don't forget that setBody will erase content of html template Prefer to use this instead. Basically you can replace setBody calls with this method URLs are rewritten by render process
- bccToAdmin() — Add in bcc admin
- bccToContact() — Add in bcc admin
- clearBody()
- doSend() — Send this email
- generatePlainPartFromBody() — Automatically adds a plain part to the email generated from the current Body
- getDisabled() — Is this email disabled ?
- getEmailTemplate() — Get the value of emailTemplate
- getFromMember() — Get sender as member
- getLocale() — Get locale set before email is sent
- getRenderedBody() — Get body of message after rendering Useful for previews
- getSendStatus() — Returns one of the STATE_xxxx constant
- getSendingCancelled() — Was sending cancelled ?
- getSentMail() — The last result from "send" method. Null if not sent yet or sending was cancelled
- getToMember() — Get recipient as member
- makeTemplateCode() — Make a template code
- render() — Render the email
- renderWithData() — Helper method to render string with data
- send() — Sends a HTML email
- sendPlain() — Sends a plain text email
- setBody()
- setData()
- setDisabled() — Disable this email (sending will have no effect)
- setEmailTemplate() — Set the value of emailTemplate
- setFrom() — Improved set from that supports Name <my@domain.com> notation
- setFromMember() — Set From Member
- setHTMLTemplate() — Set the template to render the email with
- setLocale() — Set locale to set before email is sent
- setSubject()
- setTo() — Set recipient(s) of the email
- setToAdmin() — Send to admin
- setToContact() — Set to
- setToMember() — Set a member as a recipient.