You are here

swiftmailer.module in Swift Mailer 7

Same filename and directory in other branches
  1. 8.2 swiftmailer.module
  2. 8 swiftmailer.module

This is the primary module file.

File

swiftmailer.module
View source
<?php

/**
 * @file
 * This is the primary module file.
 */

// Define permissions.
define('SWIFTMAILER_ADMINISTER', 'swiftmailer_administer');

// Define message formats.
define('SWIFTMAILER_FORMAT_PLAIN', 'text/plain');
define('SWIFTMAILER_FORMAT_HTML', 'text/html');

// Define transport types.
define('SWIFTMAILER_TRANSPORT_SMTP', 'smtp');
define('SWIFTMAILER_TRANSPORT_SENDMAIL', 'sendmail');
define('SWIFTMAILER_TRANSPORT_NATIVE', 'native');
define('SWIFTMAILER_TRANSPORT_SPOOL', 'spool');

// Define header types.
define('SWIFTMAILER_HEADER_TEXT', 'text');
define('SWIFTMAILER_HEADER_PARAMETERIZED', 'parameterized');
define('SWIFTMAILER_HEADER_MAILBOX', 'mailbox');
define('SWIFTMAILER_HEADER_DATE', 'date');
define('SWIFTMAILER_HEADER_ID', 'ID');
define('SWIFTMAILER_HEADER_PATH', 'path');

// Define system variables defaults.
define('SWIFTMAILER_VARIABLE_RESPECT_FORMAT_DEFAULT', FALSE);
define('SWIFTMAILER_VARIABLE_CONVERT_MODE_DEFAULT', FALSE);
define('SWIFTMAILER_VARIABLE_CONVERT_LIBRARY_DEFAULT', 'html2text');
define('SWIFTMAILER_VARIABLE_CONVERT_LIBRARY_MAILSYSTEM', 'mailsystem');
define('SWIFTMAILER_VARIABLE_PATH_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_FORMAT_DEFAULT', 'text/plain');
define('SWIFTMAILER_VARIABLE_TRANSPORT_DEFAULT', 'native');
define('SWIFTMAILER_VARIABLE_SMTP_HOST_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_SMTP_PORT_DEFAULT', '25');
define('SWIFTMAILER_VARIABLE_SMTP_ENCRYPTION_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_SMTP_USERNAME_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_SMTP_PASSWORD_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_SENDMAIL_PATH_DEFAULT', '/usr/sbin/sendmail');
define('SWIFTMAILER_VARIABLE_SENDMAIL_MODE_DEFAULT', 'bs');
define('SWIFTMAILER_VARIABLE_CHARACTER_SET_DEFAULT', 'UTF-8');
define('SWIFTMAILER_VARIABLE_SPOOL_DIRECTORY_DEFAULT', sys_get_temp_dir() . '/swiftmailer-spool');

/**
 * Implements hook_menu().
 */
function swiftmailer_menu() {
  $items['admin/config/people/swiftmailer'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => 'E-mail delivery',
    'description' => 'Configure settings for e-mail delivery.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'swiftmailer_admin_default_form',
    ),
    'file' => 'includes/pages/swiftmailer_admin_default.inc',
    'access arguments' => array(
      SWIFTMAILER_ADMINISTER,
    ),
  );
  $items['admin/config/people/swiftmailer/default'] = array(
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'title' => 'Library',
    'description' => 'Configure where the Swift Mailer Library is located.',
    'weight' => -10,
  );
  $items['admin/config/people/swiftmailer/transport'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Transport',
    'description' => 'Configure how Swift Mailer will send e-mails.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'swiftmailer_admin_transport_form',
    ),
    'file' => 'includes/pages/swiftmailer_admin_transport.inc',
    'access arguments' => array(
      SWIFTMAILER_ADMINISTER,
    ),
  );
  $items['admin/config/people/swiftmailer/messages'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Messages',
    'description' => 'Configure how Swift Mailer will compose messages.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'swiftmailer_admin_messages_form',
    ),
    'file' => 'includes/pages/swiftmailer_admin_messages.inc',
    'access arguments' => array(
      SWIFTMAILER_ADMINISTER,
    ),
    'weight' => 2,
  );
  $items['admin/config/people/swiftmailer/test'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Test',
    'description' => 'Send a test e-mail to verify that the configuration works.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'swiftmailer_admin_test_form',
    ),
    'file' => 'includes/pages/swiftmailer_admin_test.inc',
    'access arguments' => array(
      SWIFTMAILER_ADMINISTER,
    ),
    'weight' => 2,
  );
  return $items;
}

/**
 * Implements hook_mail().
 */
function swiftmailer_mail($key, &$message) {
  global $user;

  //$message['params']['format'] = SWIFTMAILER_FORMAT_HTML;
  $text[] = '<h3>' . t('Dear !user,', array(
    '!user' => $user->name,
  )) . '</h3>';
  $text[] = '<p>' . t('This e-mail has been sent from !site by the Swift Mailer module. The module has been successfully configured.', array(
    '!site' => variable_get('site_name', 'a Drupal site'),
  )) . '</p>';
  $text[] = t('Kind regards') . '<br /><br />';
  $text[] = t('The Swift Mailer module');
  $message['subject'] = t('Swift Mailer has been successfully configured!');
  $message['body'] = $text;
}

/**
 * Implements hook_theme().
 */
function swiftmailer_theme($existing, $type, $theme, $path) {
  $config = array(
    'swiftmailer' => array(
      'template' => 'swiftmailer',
      'variables' => array(
        'message' => '',
      ),
      'path' => drupal_get_path('module', 'swiftmailer') . '/includes/theme',
      'mail theme' => TRUE,
    ),
  );
  return $config;
}

/**
 * Implements hook_permission()
 */
function swiftmailer_permission() {
  return array(
    SWIFTMAILER_ADMINISTER => array(
      'title' => t('Administer Swift Mailer'),
    ),
  );
}