You are here

amazon_ses.module in Amazon SES 6

Same filename and directory in other branches
  1. 7.2 amazon_ses.module
  2. 7 amazon_ses.module

Enables Drupal to send email directly through Amazon SES.

Overriding mail handling in Drupal to make Amazon SES the default transport layer, requires to change the mail_system variable's default value array('default-system' => 'DefaultMailSystem'). This module uses array('default-system' => 'AmazonSESMailSystem').

File

amazon_ses.module
View source
<?php

// $Id$

/**
 * @file
 * Enables Drupal to send email directly through Amazon SES.
 *
 * Overriding mail handling in Drupal to make Amazon SES the default
 * transport layer, requires to change the mail_system variable's
 * default value array('default-system' => 'DefaultMailSystem').
 * This module uses array('default-system' => 'AmazonSESMailSystem').
 */

/**
 * Implementation of hook_help().
 */
function amazon_ses_help($path, $arg) {
  switch ($path) {
    case 'admin/help#amazon_ses':
      return t('Allow for site emails to be sent through Amazon SES.');
  }
}

/**
 * Implementation of hook_menu().
 */
function amazon_ses_menu() {
  $items['admin/settings/amazon_ses'] = array(
    'title' => 'Amazon SES',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'amazon_ses_admin_settings',
    ),
    'access arguments' => array(
      'administer amazon ses module',
    ),
    'description' => 'Allow for site emails to be sent through Amazon SES.',
    'file' => 'amazon_ses.admin.inc',
  );
  $items['admin/reports/amazon_ses'] = array(
    'title' => 'Amazon SES Statistics',
    'page callback' => 'amazon_ses_admin_stats',
    'access arguments' => array(
      'administer amazon ses module',
    ),
    'description' => 'View Amazon SES email sending statistics.',
    'file' => 'amazon_ses.admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_permission().
 */
function amazon_ses_perm() {
  return array(
    'administer amazon ses module',
  );
}

/**
 * Implementation of hook_mail().
 */
function amazon_ses_mail($key, &$message, $params) {
  if ($key == 'amazon-ses-test') {
    $message['subject'] = $params['subject'];
    $message['body'] = $params['body'];
  }
}

/**
 * Determine if Amazon SES is used to deliver e-mails.
 */
function amazon_ses_enabled() {
  return strpos(variable_get('smtp_library', ''), 'amazon_ses');
}
if (amazon_ses_enabled() && !function_exists('drupal_mail_wrapper')) {

  /**
   * Implementation of drupal_mail_wrapper().
   */
  function drupal_mail_wrapper($message) {
    module_load_include('inc', 'amazon_ses', 'amazon_ses.mail');
    return amazon_ses_send($message);
  }
}

/**
 * Implementation of hook_mailengine().
 */
function amazon_ses_mailengine($op, $message = array()) {
  switch ($op) {
    case 'name':
      return t('Amazon SES');
    case 'description':
      return t('Mailing engine using the Amazon SES library.');
    case 'settings':
      module_load_include('inc', 'amazon_ses', 'amazon_ses.admin');
      return amazon_ses_admin_settings();
    case 'multiple':
    case 'single':
    case 'send':
      module_load_include('inc', 'amazon_ses', 'amazon_ses.mail');
      return amazon_ses_send($message);
  }
}

Functions

Namesort descending Description
amazon_ses_enabled Determine if Amazon SES is used to deliver e-mails.
amazon_ses_help Implementation of hook_help().
amazon_ses_mail Implementation of hook_mail().
amazon_ses_mailengine Implementation of hook_mailengine().
amazon_ses_menu Implementation of hook_menu().
amazon_ses_perm Implementation of hook_permission().