How to create custom email headers

前端 未结 4 632
南笙
南笙 2021-02-02 10:03

I\'m trying to create a custom email header to use the SendGrid api.

Here\'s what I\'m doing - but its not working:

class Mailman < ActionMailer::Ba         


        
4条回答
  •  清歌不尽
    2021-02-02 10:27

    You can use the #headers method of ActionMailer, I've edited your example to show how:

    class Mailman < ActionMailer::Base
      default :from => "info@sample.com"
    
      def send_message(name, email, message)
        @name = name
        @email = email
        @message = message
    
        headers['X-SMTPAPI'] = '{"category": "Drip Email"}'
    
        mail(
         :to => 'info@sample.com',
         :from => email,
         :subject => "Message from the site"
        )
      end
    
    end
    

    Alternatively, you can pass a hash as an argument (to the method #headers) too:

    headers {"SPECIFIC-HEADER-1" => "value", "ANOTHER-HEADER" => "and so..."}
    

    I hope this can help you, and if not you always can check the rails guides: http://edgeguides.rubyonrails.org/action_mailer_basics.html.

提交回复
热议问题