CommentFileSizeAuthor
#10 sendgrid_template_2.patch837 bytesMatt B
#6 sendgrid_template.patch973 bytesMatt B
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Perignon created an issue. See original summary.

Perignon’s picture

Status: Active » Postponed

This is on hold till I can get this finished: https://github.com/taz77/sendgrid-php-ng/issues/3

Alex Bukach’s picture

@Perignon, did you start any work on this? I would like to contribute to this functionality if possible, since I need in on an ongoing project.

Perignon’s picture

Be glad to get any help possible. I just moved back to the US from Europe so I will not be able to do any Drupal coding for weeks.

johannez’s picture

I might post a proper patch for this later, but in the mean time I can tell you how I enabled Sendgrid templates.

First in your own _mail() or _mail_alter() function you want to attach the template_id and variables substitutions like this

$message['sendgrid'] = [
                'template_id' => 'TEMPLATE_ID',
                'substitutions' => [
                    '-name-' => [$name],
                    '-reset_url-' => [$url]
                ]
            ];

Then unfortunately you have to hack the mail() function in the sendgrid.mail.inc file.
I put it in the area where the $sendgrid_message object gets all the sets..

if(!empty($message['sendgrid']['template_id'])) {
  $sendgrid_message->setTemplateId($message['sendgrid']['template_id']);
}

if (!empty($message['sendgrid']['substitutions'])) {
  $sendgrid_message->setSubstitutions($message['sendgrid']['substitutions']);
 }
Matt B’s picture

Version: 7.x-1.x-dev » 7.x-1.1
Status: Postponed » Needs review
FileSize
973 bytes

I can confirm johannez's hack works. Here is the patch for sendgrid.mail.inc

Perignon’s picture

Patch needs to be made against the root of the module, not your site :-D

If you can fix the patch I would be happy to commit it.

Perignon’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

And also create the patch against dev, never create a patch against a release on any module on D.O

Perignon’s picture

Status: Needs review » Needs work
Matt B’s picture

Status: Needs work » Needs review
FileSize
837 bytes

Ok try this one then, previously I had just used the patch generated from the PAAS I use, whereas I've now cloned 7.x-1.x and created this patch on my local machine.

  • Perignon committed 003df34 on 7.x-1.x authored by Matt B
    Issue #2696753 by Matt B: Support SendGrid's hosted templates
    
Perignon’s picture

Patch has been committed to 7.x-1.x branch.

retrodans’s picture

I have been working on my own mapping implementation (as per issue https://www.drupal.org/node/2821974), and have integrated so the code in this patch. But my finding was that you need to include the below line for it to work with HTML templates along with setTemplateId for it to use the HTML template (otherwise you just get the plain text template)

$sendgrid_message->setHtml(' ');

Did you have a different workaround for this? Wonder if it also needs to be part of this patch for it to work with HTML templates.

As we maybe only want this for some users, maybe a config setting like the others would be a solution

Dan

Perignon’s picture

This problem may be with the wrapper library. I am rewriting the library to use the V3 API from Sendgrid. You can follow along with that development here:
https://github.com/taz77/sendgrid-php-ng/tree/v3-api-upgrade

I am working on rewriting all the unit tests right now. I have not tested this code against the API yet.

Perignon’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

drfuzetto’s picture

When I add a template_id to $message['sendgrid']['template_id'], it gets posted to SendGrid but SendGrid blocks it from being sent out.
I am getting this:
"This email was not sent because the SMTPAPI header was invalid."

Doesn't really say what is invalid. If I don't include the template_id, the email is sent ok.

Anyone else have this issue?

asak’s picture

@drfuzetto - 2 things to solve that:
1. make sure you're using the legacy templates, not the new version.
2. add $message['headers']['content-type']= 'text/html'; to the mail_alter hook.