Making Postmark 6.x work with Mime Mail

Created on 23 January 2014, almost 11 years ago
Updated 27 September 2023, about 1 year ago

I noticed that the Postmark 6.x version does not work with Mime Mail. On the Mime Mail config screen, I can choose Postmark, but mail does not send.

I realized the problem was within the postmark_mailengine() function: it was missing a 'send' option. Below is code that rectifies this:

/**
 * Implementation of hook_mailengine().
 */
function postmark_mailengine($op, $message = array()) {
  switch ($op) {
+   case 'send':
+     $message['from'] = 'itadmin@alleghenyfinancial.com';
+     $message['to'] = $message['address'];
+     $message['from'] = $message['sender'];
+     $message['language'] = NULL;
+     $message['params'] = '';
+     module_load_include('inc', 'postmark', 'includes/postmark.drupal');
+     return postmark_send($message);
+     break;
		
    case 'name':
      return t('Postmark');
      
    case 'description':
      return t('Mailing engine using the Postmark library.');
      
    case 'settings':
      module_load_include('inc', 'postmark', 'postmark.admin');
      return postmark_settings_form();
  }
}

In the above code, the 'send' option in the case switch has been added.

Also, we needed a postmark_prepare_message(), I think. Without it, Mime Mail was preparing the message in a way that put both parts of the multipart email (both plain text and HTML) into the same mail body.

Below is the code I added, adapted from Mime Mail:

function postmark_prepare_message($sender, $recipient, $subject, $body, $plaintext = NULL, $headers = array(), $text = NULL, $attachments = array(), $mailkey = '') {
  module_load_include('inc', 'mimemail');
	
  $plaintext = $plaintext || variable_get('mimemail_textonly', 0);
  $sender    = mimemail_address($sender);
  $subject = mime_header_encode($subject);
  $mail      = mimemail_html_body($body, $subject, $plaintext, $text, $attachments);
  $headers   = array_merge($headers, $mail['headers']);
  $message   = array(
    'address' => mimemail_address($recipient),
    'subject' => $subject,
    'body'    => $body,
    'sender'  => $sender,
    'headers' => mimemail_headers($headers, $sender),
  );
  return $message;
}

With this code added, I can now choose Postmark as the chosen mail engine for Mime Mail.

πŸ› Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States visuaLatte

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024