View source
<?php
define('AMAZON_SES_REQUEST_FALIURE', 0);
define('AMAZON_SES_REQUEST_SUCCESS', 1);
function amazon_ses_permission() {
return array(
'amazon_ses_configuration' => array(
'title' => t('Configure Amazon Simple Email Service'),
),
);
}
function amazon_ses_menu() {
$items['admin/config/services/amazon-ses'] = array(
'title' => 'Amazon SES Settings',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_config_form',
),
'file' => 'includes/amazon_ses.admin.inc',
);
$items['admin/config/services/amazon-ses/settings'] = array(
'title' => 'Amazon SES Settings',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_config_form',
),
'file' => 'includes/amazon_ses.admin.inc',
);
$items['admin/config/services/amazon-ses/verify-ses-sender-id'] = array(
'title' => 'Verify Sender ID',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_verify_sender_id_form',
),
'file' => 'includes/amazon_ses.admin.inc',
'weight' => 2,
);
$items['admin/config/services/amazon-ses/sender-id-list'] = array(
'title' => 'Sender ID List',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_identity_list_form',
),
'file' => 'includes/amazon_ses.admin.inc',
'weight' => 3,
);
$items['admin/config/services/amazon-ses/dkim-setup'] = array(
'title' => 'DKIM Setup',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_domain_dkim_enable_form',
),
'file' => 'includes/amazon_ses.admin.inc',
'weight' => 4,
);
$items['admin/config/services/amazon-ses/statistics'] = array(
'title' => 'SES Statistics',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_get_mail_statistics_form',
),
'file' => 'includes/amazon_ses.admin.inc',
'weight' => 5,
);
$items['admin/config/services/amazon-ses/sender-config'] = array(
'title' => 'Sender Configuration',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'amazon_ses_configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'amazon_ses_sender_configuration_form',
),
'file' => 'includes/amazon_ses.admin.inc',
'weight' => 6,
);
return $items;
}
function amazon_ses_form_amazon_ses_domain_dkim_enable_form_alter(&$form, &$form_state) {
if (isset($form_state['values'])) {
if ($form_state['values']['update'] == $form_state['triggering_element']['#value']) {
$selected_row = $form_state['values']['list_table'];
$action_parameter['Identities'] = array(
$form_state['complete form']['amazon_list_identities_update']['list_table']['#options'][$selected_row]['Identity'],
);
$result = amazon_ses_send_request('GetIdentityDkimAttributes', $action_parameter);
if ($result['error']) {
amazon_ses_set_error_message('GetIdentityDkimAttributes', $result);
}
else {
$form['div']['domain_dkim_token_table']['#options'] = $result['member'];
foreach ($result['member'] as $key => $value) {
$form['div']['domain_dkim_token_table'][$key]['#disabled'] = TRUE;
}
$form['div']['domain_dkim_token_table']['#access'] = TRUE;
$help = t('DKIM settings for your domain have been generated.</strong>') . '<br/>';
$help .= t("The information below must be added to your domain's DNS records. How you update the\n DNS settings depends on who provides your DNS service, if your DNS service is provided by a domain name registrar, please contact that registrar to update your DNS records. <a href='@learn_dkim'>Learn More about DKIM</a>", array(
'@learn_dkim' => 'http://docs.aws.amazon.com/ses/latest/DeveloperGuide/dkim.html',
));
$help .= '<br/>' . t('<strong>DKIM:</strong> Waiting on sender verification.') . '<br/>';
$help .= t('<strong>DKIM Verification Status:</strong> @status', array(
'@status' => $result['DkimVerificationStatus'],
));
$help .= '<br/>' . t('To enable DKIM signing for your domain, the records below must be entered in your DNS settings. AWS will automatically detect the presence of these records, and allow DKIM signing at that time. Note that verification of these settings may take up to 72 hours.');
$form['div']['domain_dkim_info']['#prefix'] = "<div id=domain_dkim_info><strong>" . $help . "<br/>";
$form['div']['domain_dkim_info']['#suffix'] = '</div>';
}
}
}
}
function amazon_ses_verify_email_identity_amazon($element, &$form_state) {
if (isset($element['#value'])) {
$action_parameter['Identities'][] = $element['#value'];
$result = amazon_ses_send_request('GetIdentityVerificationAttributes', $action_parameter, '');
switch ($result['status']) {
case AMAZON_SES_REQUEST_SUCCESS:
if (isset($result['token']['row0']['VerificationStatus'])) {
$id_status = $result['token']['row0']['VerificationStatus'];
if ($id_status == 'Pending') {
form_error($element, t('@email address is in pending state, yet not verified by Amazon SES. \\n so Please contact amazon SES or change the mail', array(
'@email' => $element['#value'],
)));
}
}
else {
form_error($element, t('Please send request for verifying @email address to Amazon SES, Or change the mail', array(
'@email' => $element['#value'],
)));
}
break;
case AMAZON_MAIL_SERVICE_REQUEST_EXCEPTION:
form_error($element, t('Sending request to amazon is failed!, Please try again'));
break;
}
}
}
function getAmazonSes() {
$key = variable_get('amazon_ses_key', '');
$secret = variable_get('amazon_ses_secret', '');
$region = variable_get('amazon_ses_region', '');
if (!empty($key) && !empty($secret) && !empty($region)) {
return new \Drupal\amazon_ses\AmazonSes($region, $key, $secret);
}
else {
return FALSE;
}
}
function amazon_ses_send_request($query_action, $action_parameters) {
$amazon_ses = getAmazonSes();
if ($amazon_ses) {
$result = $amazon_ses
->performServiceAction($query_action, $action_parameters);
return $result;
}
else {
drupal_set_message(t('Please configure amazon ses !here', array(
'!here' => l(t('here'), 'admin/config/services/amazon-ses/settings'),
)), 'error');
return FALSE;
}
}
function amazon_ses_set_error_message($action, $result) {
$message = t('Request to <strong>!action</strong> action of Amazon
SES API call has failed, due to !error_code. Please check settings.', array(
'!error_code' => $result['errorCode'],
'!action' => $action,
));
drupal_set_message($message, 'error');
}