I have Sendgrid Integration installed and working, but need it to send HTML emails.

I have installed the recommended HTML mail module but I must be missing something.

I can see the option to send email via HTMLmailsystem, or via Sendgridmailsystem, but I can't work out how to use HTMLmail to do the HTML formatting but have the actual emails come through Sendgrid.

If I set the mail system settings to use HTMLmail the emails don't come from Sendgrid but are sent direct by the server. If I set them to use Sendgrid, they do, but are not formatted as HTML.

CommentFileSizeAuthor
#2 Screen Shot 2016-10-12 at 21.41.26.png20.14 KBPerignon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cycas created an issue. See original summary.

Perignon’s picture

Issue summary: View changes
FileSize
20.14 KB

You have to create a new class that uses HTMLmail for processing and SendGrid for sending.

Like this:

cycas’s picture

I tried that, but the new class gave me this error when I tried to use it :

GuzzleHttp\Exception\ClientException: Client error: `POST https://api.sendgrid.com/api/mail.send.json` resulted in a `400 Bad Request` response: {"errors":["Missing email body"],"message":"error"} in GuzzleHttp\Exception\RequestException::create() (line 107 of /home/tavata/public_html/sites/all/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).

I get that both from Views Send and from the HTML Mail Test mail functionality when I use the HTMLMailSystem__SendGridMailSystem class.

Did you have to make a change to the HTMLmail template to get Sendgrid to accept the format or something?

Perignon’s picture

Can you send an email using the testing function in the Sendgrid module?

cycas’s picture

I can send an email via Sendgrid's testing function, but not in HTML format. It arrives displaying unformatted HTML if I try to send a Full HTML email.

I tried experimenting with the filters in HTMLmail and if everything is set to filtered HTML, then I can send email using Views Send or HTMLmail test, but the emails don't come out formatted.

I feel like I'm missing something obvious here. :-(

Perignon’s picture

Have you configured/made templates for HTMLmail?

cycas’s picture

Yes, I made a copy of the generic template. I assume it must be working if I can send via HTMLmail and the local server and have HTML email arrive, but not send HTML via Sendgrid?

cycas’s picture

... OK, I finally got this working by reinstalling the Mime Mail module and setting up a MimeMailSystem_SendgridSystem class to use with Views Send module at admin/config/system/mailsystem, instead of HTMLmail .

I know Mimemail module isn't supposed to work with Sendgrid module, but what can I say, apparently it does for me, and HTMLmail doesn't.

Views Send does say that it won't send HTML unless Mimemail is installed, so that may be where some of my issues were coming from.

Perignon’s picture

Status: Active » Fixed

Glad that you got something working. I use HTMLmail and the Sendgrid module a lot so the problems may stem from Views Send. The Views Send module seems to be peculiar in how it works. Other have posted problems with that module.

Status: Fixed » Closed (fixed)

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

Matt B’s picture

I couldn't get either to work. However putting
$message['headers']['content-type']= 'text/html';
in my _mail_alter() in a custom module did the trick....

ryank76’s picture

#8 worked for me too, thank you!

chicagomom’s picture

When I tried to create a new class as #2, I get: Fatal error: Class 'HTMLMailSystem__SendGridMailSystem' not found in /.../sites/all/modules/mailsystem/mailsystem.module on line 293.

sam452’s picture

Coming in late here. When you created MimeMailSystem_SendgridSystem class did you just duplicate a rename the MimeMail class in mimemail/src/Plugin/Mail/ ? What is in this class and where should it be placed to be picked up by the mail system? In its own module?

Perignon’s picture

This is performed in the UI, not in the source code (Relative URL: admin/config/system/mailsystem)

wOOge’s picture

Here's what I had to do:

  1. WARNING: BACKUP EVERYTHING FIRST!!!!!!!
  2. Disable: MimeMail, SendGrid Integration, Mail System, HTML Mail
  3. Uninstall: MimeMail, SendGrid Integration, Mail System, HTML Mail
  4. Re-Enable: SendGrid Integration, Mail System, HTML Mail
  5. Navigate to: /admin/config/system/mailsystem
  6. Create a "New Class", by scrolling down the page, expanding the fieldset for "New Class", Select "HTML Mail" for "format()" and "SendGrid" for "mail()".
  7. Click "Save Settings".
  8. At this point I got an error, that locked up my whole site. I noticed that the New Class file HTMLMailSystem__SendGridMailSystem.mail.inc was saved in /srv/private_files/. But Drupal couldn't find it. So I had to move it to a new location and change the perms on it.
  9. On your server, create a new directory in /sites/default/files/mailsystem. So the path should be: /sites/default/files/mailsystem.
  10. Next Move the New Class file to this new location. Something like this: mv /srv/private_files/HTMLMailSystem__SendGridMailSystem.mail.inc /srv/www/website.com/sites/default/files/mailsystem
  11. Next change the perms on the HTMLMailSystem__SendGridMailSystem.mail.inc file to something like 755
  12. Next, edit the Drupal Database. I use SequelPro
  13. WARNING: BACKUP YOUR DATABASE FIRST!!!!!!!
  14. Ok, now that you have a safe and working backup (or two), locate the registry table.
  15. In the data, locate a row with the name of HTMLMailSystem__SendGridMailSystem
  16. Change the path in the filename column, to match the new location of your New Class file, BUT MAKE IT RELATIVE to your web root. For example: sites/default/files/mailsystem/HTMLMailSystem__SendGridMailSystem.mail.inc
  17. Save your changes.
  18. Clear caches. I use: drush cc all
  19. Then go to admin/config/system/mailsystem and set your settings to this:
    1. Site-wide default: HTMLMailSystem__SendGridMailSystem
    2. SendGrid Integration module class: SendGridMailSystem
    3. HTML Mail module class: HTMLMailSystem
    4. Theme: To your desired theme (ensure you have the HTML Mail templates in there as per HTMLMail instructions).

That's what I had to do on Drupal 7.63 with the latest version of all modules involved at this time.
I hope that helps someone.

daggar’s picture

Thanks to wOOge for #16 . That works for me, as of Drupal 7.67.

I modified his routine slightly; putting the template in the publically-accessible files directory made me nervous.

Instead, I put mine in the less-vulnerable theme directory. So, instead of
sites/default/files/mailsystem/HTMLMailSystem__SendGridMailSystem.mail.inc

I placed mine in
sites/all/themes/[site_theme_dir]/HTMLMailSystem__SendGridMailSystem.mail.inc

...where [site_theme_dir] is changed to the directory of your specific install's theme.

Then I updated the database entry accordingly to that changed path, and it works.

daggar’s picture

finaukaufusi’s picture

The important part of this, is the "Database update" to the registry table. You don't need to un-install and re-install the modules. Just make sure the value inside the registry table is correct. Eg, the path is correct.

npoku’s picture

Confirm firming #11 worked for me.

Running: Drupal 7.69
Sendgrid Integration: 7.x-1.4+6-dev
HTML Mail: 7.x-2.71
Mime (just in case you need it, why not) 7.x-1.1)
Host: Pantheon

Just for my sanity & future reference....
In my case, I kept on getting a MIME encoded message on top of my actual correctly formatted HTML message body. This was being caused by routing my HTML formatted message via Sendgrid. Solution is to turn off Step 3 "Provide simple plain/text alternative of the HTML mail." on the HTML module settings page (/admin/config/system/htmlmail). Hope this helps someone in future.