Setting Custom Headers When Sending A Message

155 views
Skip to first unread message

Chris Rothstein

unread,
Jun 20, 2013, 3:45:53 AM6/20/13
to mail...@googlegroups.com
I am using the mail gem and I was curious if anyone knows how to setup custom headers.  I am using Mailgun for sending email and I am trying to pass a custom variable to them via a header.  I need to send over a header with the name "X-Mailgun-Variables" and a value that is a string. I can't seem to find any documentation on how to do this. My code is below:

mail = Mail.deliver do
      to to
      from "#{name} <#{from}>"
      subject subject
      bcc bcc_to
      
      text_part do
        body text
      end 
      if user_has_signature
        html_part do
          content_type 'text/html; charset=UTF-8'
          body html_text
        end
      end

Patrick Veverka

unread,
Apr 21, 2014, 7:06:03 PM4/21/14
to mail...@googlegroups.com
Try this:

mail = Mail.new do
  to to
  from "#{name} <#{from}>"
  subject subject
  bcc bcc_to
      
  text_part do
    body text
  end 
  if user_has_signature
    html_part do
      content_type 'text/html; charset=UTF-8'
      body html_text
    end
  end
end

mail['X-Mailgun-Variables'] = "YOUR STRING"
mail.deliver!
Reply all
Reply to author
Forward
0 new messages