

Now you need a custom mail system class which would use the format() method from one mail system class and it would use the mail() method from another class. Each one has a format() and a mail() method. Imagine you have two or more different mail system classes available in your system provided by different modules. The Mail System module checks every theme registry entry for a specific “mail theme” key/property and if it exists in a particular entry then the specified mailsystem_theme value will be used to search for more specific template files when the theme registry entry related theme hook will be called. The mentioned template file obviously belongs to a hook_theme() entry to be able to use it at appropriate theme() calls. let's assume that there is a drupal mail system related module which uses a template file to render emails. The mailsystem_theme key is a little bit different since it defines which theme will be used to render the emails. As you can see its default value is DefaultMailSystem so this is the reason why this mail system class will be used by drupal_mail() by default. The default-system “email key” always exists and it determines which mail system class will be used by default for all outgoing emails. The Mail System module related settings can be found under the Configuration > System > Mail System path It allows you to adjust the mail_system variable by an administrative UI and it provides some other useful configuration options, too. This is the point where the Mail System module comes in. In Drupal 7, that must be enabled for each template, in Drupal 8, it works reliably for any template being rendered while building and sending e-mails.ĭrupal 7 don’t provide administrative UI to adjust the mail_system variable which defines “email key” => “mail system class” type key-value pairs which correspond to what mail system class will be used by drupal_mail() at a specific email key. Additionally, a theme can be configured that is used for sent mails. Allow to use different backends for formatting and sending e-mails by default, per module and per mail key. Mail system module in drupal provides an Administrative UI and Developer API for managing the used email/plugin. Will discuss this class in more detail first, let’s check out drupal 7 mail system module. By default drupal uses DefaultMailSystem class to send email.

So you can understand better that mailsystem plays an important role while sending email. send email using mail() method of the called mail system class.

Format the email message using format() method of the called mail system class.Check for the responsible mail interface system which will handle the email.Allows module to alter email by calling hook_mail_alter().Build email(subject, body, with other required parameters) by calling hook_mail().Set up default email messages properties.Second method mail() method defines the exact email sending behaviour. MailsystemInterface class uses two methods 1) format() and 2) mail()Īs you can get it from name itself the first method format() method is used for formatting an email before it get send. Every mail system needs to implement MailSystemInterface class to declare own sending behaviour. While sending an email drupal_mail() function uses system class for sending an email. In this article I’ll show you how you can customize and extend the Drupal mail system to fulfill your needs. But Drupal gives us a Flexibility to customize email sending process, before that it’s necessary to know how stuff works behind the scenes first. However in the scenario like bigger & complex site the above steps won’t be enough. Call drupal_mail() with argument for actually sending the email.Declare all the required properties under hook_mail().In Drupal to sends an email we need to take care of two rules This blog is all about How Drupal handles the Mail system & the stages it has to go through.
