README.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <h2 id="mail-system"><a href="http://drupal.org/project/mailsystem">Mail System</a></h2>
  2. <p>Provides an Administrative UI and Developers API for safely updating the <a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7">mail_system</a> configuration variable.</p>
  3. <h3 id="administrative-ui">Administrative UI</h3>
  4. <p>The administrative interface is at <code>admin/config/system/mailsystem</code>. A <a href="http://drupal.org/node/1134044">screenshot</a> is available.</p>
  5. <h3 id="used-by">Used by:</h3>
  6. <ul>
  7. <li><a href="http://drupal.org/project/htmlmail">HTML Mail</a></li>
  8. <li><a href="http://drupal.org/project/mimemail">Mime Mail 7.x-1.x-dev</a></li>
  9. <li><a href="http://drupal.org/project/postmark">Postmark 7.x-1.x</a></li>
  10. </ul>
  11. <h3 id="developers-api">Developers API</h3>
  12. <p>A module <code>example</code> with a <a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7"><code>MailSystemInterface</code></a> implementation called <code>ExampleMailSystem</code> should add the following in its <code>example.install</code> file:</p>
  13. <pre>
  14. <code>/**
  15. * Implements hook_enable().
  16. */
  17. function example_enable() {
  18. mailsystem_set(array('example' => 'ExampleMailSystem'));
  19. }
  20. /**
  21. * Implements hook_disable().
  22. */
  23. function example_disable() {
  24. mailsystem_clear(array('example' => 'ExampleMailSystem'));
  25. }
  26. </code>
  27. </pre>
  28. <p>The above settings allow mail sent by <code>example</code> to use <code>ExampleMailSystem</code>. To make <code>ExampleMailSystem</code> the site-wide default for sending mail:</p>
  29. <pre>
  30. <code>mailsystem_set(array(mailsystem_default_id() => 'ExampleMailSystem'));
  31. </code>
  32. </pre>
  33. <p>To restore the default mail system:</p>
  34. <pre>
  35. <code>mailsystem_set(array(mailsystem_default_id() => mailsystem_default_value()));
  36. </code>
  37. </pre>
  38. <p>Or simply:</p>
  39. <pre>
  40. <code>mailsystem_set(mailsystem_defaults());
  41. </code>
  42. </pre>
  43. <p>If module <code>example</code> relies on dependency <code>foo</code> and its <code>FooMailSystem</code> class, then the <code>example.install</code> code should like like this:</p>
  44. <pre>
  45. <code>/**
  46. * Implements hook_enable().
  47. */
  48. function example_enable() {
  49. mailsystem_set(array('example' => 'FooMailSystem'));
  50. }
  51. /**
  52. * Implements hook_disable().
  53. */
  54. function example_disable() {
  55. mailsystem_clear(array('example' => ''));
  56. }
  57. </code>
  58. </pre>
  59. <p>If module <code>example</code> only wants to use <code>FooMailSystem</code> when sending emails with a key of <code>examail</code>, then the <code>example.install</code> code should look like this:</p>
  60. <pre>
  61. <code>/**
  62. * Implements hook_enable().
  63. */
  64. function example_enable() {
  65. mailsystem_set(array('example_examail' => 'FooMailSystem'));
  66. }
  67. /**
  68. * Implements hook_disable().
  69. */
  70. function example_disable() {
  71. mailsystem_clear(array('example_examail' => ''));
  72. }
  73. </code>
  74. </pre>
  75. <h4 id="new-in-2.x-branch"><em>(New in 2.x branch)</em></h4>
  76. <p>To change the site-wide defaults to use the <code>FooMailSystem</code> for formatting messages and the <code>BarMailSystem</code> for sending them:</p>
  77. <pre>
  78. <code>mailsystem_set(
  79. array(
  80. mailsystem_default_id() =&gt; array(
  81. 'format' =&gt; 'FooMailSystem',
  82. 'mail' =&gt; 'BarMailSystem',
  83. ),
  84. )
  85. );
  86. </code>
  87. </pre>
  88. <p>To change the site-wide defaults to use the <code>FooMailSystem</code> for sending messages, while continuing to use the current system for formatting them:</p>
  89. <pre>
  90. <code>mailsystem_set(
  91. array(
  92. mailsystem_default_id() =&gt; array(
  93. 'mail' =&gt; 'FooMailsystem',
  94. ),
  95. )
  96. );
  97. </code>
  98. </pre>
  99. <h3 id="references">References</h3>
  100. <dl>
  101. <dt><strong><a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7"><code>drupal_mail_system()</code> API documentation</a></strong>:</dt>
  102. <dd>
  103. <p><a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7">api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7</a></p>
  104. </dd>
  105. <dt><strong><a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7"><code>MailSystemInterface</code> API documentation</a></strong>:</dt>
  106. <dd>
  107. <p><a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7">api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7</a></p>
  108. </dd>
  109. <dt><strong><a href="http://drupal.org/node/900794">Creating HTML formatted mails in Drupal 7</a></strong>:</dt>
  110. <dd>
  111. <p><a href="http://drupal.org/node/900794">drupal.org/node/900794</a></p>
  112. </dd>
  113. </dl>