amazon_ses.mail.inc in Amazon SES 7
File
includes/amazon_ses.mail.inc
View source
<?php
require_once 'classes/amazonses.class.php';
class AmazonSesSystem extends DefaultMailSystem {
public function format(array $message) {
$message['body'] = implode("\n\n", $message['body']);
$message['body'] = drupal_wrap_mail($message['body']);
return $message;
}
public function mail(array $message) {
$message['destination'] = array(
'ToAddresses' => explode(',', $message['to']),
);
if (!empty($message['headers']['Cc'])) {
$message['destination']['CcAddresses'] = explode(',', $message['headers']['Cc']);
}
if (!empty($message['headers']['Bcc'])) {
$message['destination']['BccAddresses'] = explode(',', $message['headers']['Bcc']);
}
$message['message']['Subject']['Data'] = $message['subject'];
$message['message']['Body']['Html']['Data'] = nl2br($message['body']);
unset($message['headers']);
unset($message['body']);
unset($message['to']);
unset($message['params']);
unset($message['subject']);
unset($message['key']);
unset($message['module']);
unset($message['language']);
unset($message['id']);
$action_parameters['mail'] = $message;
$reply_to = variable_get('amazon_ses_reply_to', $message['from']);
$return_path = variable_get('amazon_ses_return_path', $message['from']);
$opt = array();
if (!empty($reply_to)) {
$opt['ReplyToAddresses'] = $reply_to;
}
if (!empty($return_path)) {
$opt['ReturnPath'] = $return_path;
}
$action_parameters['opt'] = $opt;
$result = amazon_ses_send_request('SendEmail', $action_parameters);
if ($result['status']) {
return TRUE;
}
return FALSE;
}
}
function amazon_ses_send_request($query_action, $action_parameters) {
$amazon_mail_service = new AmazonSesClass();
$result = $amazon_mail_service
->performServiceAction($query_action, $action_parameters);
return $result;
}