Did you know that you can navigate the posts by swiping left and right?

Subscription tracking in Sendgrid and Rails 4

03 Aug 2013 . category: Quicktips . Comments

Few days ago I extracted mailer classes out of our monolith app. I created a new, small Rails 4 application which consumes RabbitMQ queue and sends emails to users. We use Sendgrid’s subscription tracking. We use particularly a placeholder, which Sendgrid replaces by unsubscription url.

  # in mailer

sendgrid_subscriptiontrack_text(:replace => '[unsubscribe]')

# in template

<a href="\[unsubscribe\]">click here.</a>

The problem was, that the placeholder [unsubscribe] was replaced by a bogus URL like x-msg://447/\[unsubscribe\]. It turns out, that Rails 4 encodes automatically all URLs in emails.

The fix

Sendgrid does not decode these URLs, so I needed to encode the placeholder.

  # in mailer

sendgrid_subscriptiontrack_text(:replace => '%5Bunsubscribe%5D')

I hope that this will save you some time.