Last Updated: February 25, 2016
·
2.17K
· 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="http://docs.sendgrid.com/documentation/apps/bypass-list-management/">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 'email@company.com'
     to 'recepient@gmail.com'
     subject 'List management'
     body 'Hello world!'
   }
}

See <a href="http://docs.sendgrid.com/documentation/apps/bypass-list-management/">SendGrid documentation</a> for more.