Last Updated: February 25, 2016
· andreitr

Bypass SendGrid's list management with sendMail

If you use SendGrid as the email service for your grails app then you probably saw a case where:

Some e-mails are too important to do normal list management checks, such as password resets or critical alerts. Enabling this filter will bypass the normal unsubscribe / bounce / spam report checks and queue the e-mail for delivery.

SendGrid has a nice feature that allows you to <a href="">bypass list management</a> by sending custom email headers. Here's how you do that in sendMail:

void testBlockedEmail() {

  def emailHeaders = [:]

  emailHeaders['X-SMTPAPI'] = new JSON(["filters":["bypass_list_management" : ["settings":["enable":1]]]])

  mailService.sendMail {
     headers emailHeaders
     from ''
     to ''
     subject 'List management'
     body 'Hello world!'

See <a href="">SendGrid documentation</a> for more.