title: Rails Mailer using SendGrid Template
body: <p>How do I tie in my rails mailer to Sendgrid using the smtpapi-ruby gem?  I've followed their <a href="https://sendgrid.com/docs/API_Reference/SMTP_API/index.html" rel="nofollow noreferrer">limited documentation</a>, but my emails aren't going through, I've verified that my SendGrid implementation works fine when just sending a plain email, so that's not it.  This is what I have:</p>
  
  <p><strong>user_controller.rb</strong></p>
  
  <pre><code>def create
      @user = User.new(user_params)
  
      respond_to do |format|
        if @user.save
          format.html { redirect_to @user, notice: 'User was successfully created.' }
          format.json { render :show, status: :created, location: @user }
  
  
          header = Smtpapi::Header.new
          header.add_to(@user.email)
          header.add_substitution('user', [@user.name])
          header.add_substitution('body', "You've registered! This is from the controller.")
          header.add_filter('templates', 'enable', 1)
          header.add_filter('templates', 'template_id', 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx')
          header.to_json
  
          UserNotifier.welcome(header).deliver
        else
          format.html { render :new }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p><strong>mailers/user_notifier.rb</strong></p>
  
  <pre><code>class UserNotifier &lt; ApplicationMailer
    default from: "test@test.com"
  
    def welcome(header)
      headers['X-SMTPAPI'] = hdr.to_json
      mail(subject: "Welcome to the site!")
    end
  end
  </code></pre>
  
  <p><strong>views/user_notifier/welcome.html.erb</strong></p>
  
  <pre><code>&lt;html&gt;
   &lt;body&gt;
     Hi -user-&lt;br /&gt;
     Thanks so much for joining us!
  
     &lt;p&gt;-body-&lt;/p&gt;
  
     Thanks,&lt;br /&gt;
     The Microblog Team
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm not seeing anything come through on the SendGrid activity log, so it's not even getting sent there, at least that's my guess.  </p>
  
  <p>What am I doing wrong?</p>