sendgrid-ruby: cc and bcc is not working

I am trying to send emails using template api

client = SendGrid::Client.new(api_user: ENV['SENDGRID_USERNAME'], api_key: ENV['SENDGRID_PASSWORD'])
@user_emails = ['abc@abc.com', 'abc2@abc.com']

@header = Smtpapi::Header.new
@header.add_to(@user_emails)
@header.add_filter('templates', 'enable', 1)    # necessary for each time the template engine is used
@header.add_filter('templates', 'template_id', template_id)
mail = SendGrid::Mail.new do |m|
      m.to = @user_emails
      m.from = from
      m.from_name = fromname
      m.bcc = bcc
      m.subject = ' '
      m.smtpapi = @header
      m.html = '<img alt="" height="1" src="" style="display:none;" width="1" />'
    end
client.send(mail)

The to is working fine , but bcc is not working . Is it some kind of bug

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

It is just adding our replacements in our email templates. Where we are doing add_substitution calls there and such. Not sure if this helps but here is a stripped down version.

class SomeHeaderBuilder
  def build_header(recipients)
    header_factory = HeaderFactory.new(recipients)

    header_factory.add_param(":welcome_message", "hey, how are ya?")

    header_factory.add_template_id(template_id)
    header_factory.header
  end

  private

  def template_id
    "12345"
  end
end
class HeaderFactory
  attr_reader :header

  def initialize(recipients, header = Smtpapi::Header.new)
    @recipients = recipients
    @header = header

    @header.add_to recipients if @header.to.empty?
  end

  def add_param(key, value)
    header.add_substitution(key, Array.new(@recipients.size, value))
  end

  def add_template_id(template_id)
    header.add_filter("templates", "enable", 1) # necessary for each time the template engine is used
    header.add_filter("templates", "template_id", template_id)
  end
end

I’m pretty sure it works now, I think it’s not an issue anymore.