rept
rept

Reputation: 2236

Tagging messages with ActionMailer and mailgun

I'm using mailgun with ActionMailer like this:

config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
  api_key: 'key-b46eXXXXXXXXXXXX91c4',
  domain: 'mg.eagle.com'
}

Mails go out like this:

mail(to: @contact, subject: 'Ask a Question', reply_to: @email, from: @email)

How can I add tags to my mails? There is an example in the mailgun documentation (https://documentation.mailgun.com/en/latest/user_manual.html#tagging) but that doesn't use ActionMailer but a POST on the API...

Upvotes: 1

Views: 422

Answers (1)

rept
rept

Reputation: 2236

I found the solution to this, it's actually pretty simple:

Put the following line before the mail command:

headers['X-Mailgun-Tag'] = 'contact_us'

However this will only work if the Pull request is merged: https://github.com/mailgun/mailgun-ruby/pull/133

Until then you can use this in the Gemfile:

gem 'mailgun-ruby', :github => 'mailgun/mailgun-ruby', :branch => 'sjohn/railgun-mailer-headers'

Upvotes: 1

Related Questions