This blog is all about Drupal Mail system. Email sending in Drupal is entirely straightforward. Essentially you just need to manage two stages to send an email to somebody:
In Drupal to sends an email we need to take care of two things:
- Declare all the required properties (subject, body, headers, etc) under hook_mail().
- Call drupal_mail() with the argument for actually sending the email.
However, in the situation like greater and complex site, the above strides won’t be sufficient. In any case, Drupal gives us the Flexibility to redo email sending process, before that it’s important to know how stuff functions in the background first, with the help of Drupal you can easily generate custom pdf using the print module. In this blog, I’ll demonstrate to you how you can redo and extend the Drupal mail framework to satisfy your necessities.
The Email Sending Process
While sending an email drupal_mail() function uses system class for sending an email. Each mail framework needs to actualize MailSystemInterface class to define its own mail sending conduct.
MailsystemInterface class utilizes two strategies:
The Mail System Module
Mail related settings can be set through Configuration > System > Mail System.
The mail system variable contains two things:
- default-system => DefaultMailSystem
- mailsystem_theme => current.
These key-value pairs are the settings you can adjust under the “Mail System Settings” fieldset.
The default-system email key describes which mail system class will be used by default for all outgoing emails.
If you don’t modify the site-wide mail system class then this one will be used by drupal_mail() by default.
The mailsystem_theme defines which theme will be used to render emails. Let’s say you are using Mime Mail which
uses a specific template file for it’s emails. 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.
If you have two or more different mail system classes available in your system provided by different modules.
If you want to use any custom mail class which would use format() method of one mail system class and mail()
method from another class, so here you can use New Class which allows combining two different mail system classes.
The Mail System module permits you to effortlessly add new email keys to the mail_system variable by choosing a
module and a particular email key from its hook_mail() execution.
Afterward added new email key to the mail_system variable you will ready to choose mail system class for it.
You will have the capacity to see it under all inclusive default MailSystemInterface class settings.
At the point when drupal_mail is called with your demo_custom _mail email key, then the in a roundabout way utilized
drupal_mail_system() function checks if this email_key exists in mail_system variable. It finds the related key then the
related mail system class will be utilized rather than default class.
Hope this helped you to get most out of the system. Feel free to share your reviews and need assistance regarding
Drupal Development Services. #WeDrupalEveryday
Pick the best answer for your requirements.