Attachments via Rules Not Being Attached with API

Created on 9 November 2017, about 7 years ago
Updated 1 June 2023, over 1 year ago
</code>Using rules to attach and send a file via sendgrid integration API doesn't seem to work. It works fine using SMTP, but when switching your site to use the API it will send the email without the file attached. 

The current configuration I was using is: MailSystem module, Rules, Sendgrid Integration module with an API key, (also webform and fillPDF, but that shouldn't be relevant).

Background: when a user filled a webform and submitted, Rules would grab the webform data, fill out a PDF, attach it to an HTML email and send it out. 

The problem was that the e-mail would go through, but the attachment wouldn't be attached when receiving it. 

The issue seemed to be that drupal / rules was sending the attachment data as $message['params']['attachments'], and sendgrid integration module was expecting it as $message['attachments'] (this is evident in sendgrid_integraiton/inc/sendgrid.mail.inc file on line 308)


In order to fix this I generated a new class .inc file with MailSystem (which generates a file in files/mailsystem folder), and overwrote the public mail function in it with the following (relevant part is bolded):

public function mail(array $message) {
   
      /** fix the missing attachments problem **/
<code>
      if(!empty($message['params']['attachments'])){
                    
          $message['attachments'] = $message['params']['attachments'];
          
          foreach($message['attachments'] as $key => $value){
              if(!empty($value['filepath'])){
                  $message['attachments'][$key] = $value['filepath'];
              }
          }
         
      }

/** fix the reply-to problem **/

if(!empty($message['params']['reply-to'])){
$message['headers']['Reply-To'] = trim($message['params']['reply-to']);
}

return $this->mailClass->mail($message);
}

A more permanent fix would be to modify the inc/sengrid.mail.inc file on line 306 to see if $message['params']['attachments'] was empty or not and, if not, to add it's contents to the $message['attachments'] array in the appropriate format.

πŸ› Bug report
Status

Needs work

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States supergecko28

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