Coder Social home page Coder Social logo

Comments (17)

itsmatthu avatar itsmatthu commented on July 18, 2024 1

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

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024 1

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

from sendgrid-ruby.

aelor avatar aelor commented on July 18, 2024

Its still not working @matt-hu . We ran a test just now.

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

We have not been able to get this to work either @matt-hu . Both cc and bcc. We have tried switching on the bcc flag in our account settings as well and it doesn't seem to be the issue.

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

@thinkingserious please see above.

from sendgrid-ruby.

thinkingserious avatar thinkingserious commented on July 18, 2024

@aelor, @davidsavoya,

Are you using the new library? https://github.com/sendgrid/sendgrid-ruby/tree/v3beta

In either case, could you provide me with the code (credentials and sensitive data redacted)?

Thanks!

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

No I am on version 1.1.6.

def build_email(recipients, header_builder, files = {})
      attachments = files.map do |key, value|
        {name: key, file: value}
      end

      mail = SendGrid::Mail.new do |m|
        m.to = recipients
        m.bcc = "[email protected]"
        m.from = from_address
        m.subject = " "
        m.html = "<body></body>"
        m.attachments = attachments
      end

      mail.smtpapi = header_builder.build_header(recipients)
      mail
    end

then call client.send(mail) where ever we are using this.

Everything else is working as expected.

from sendgrid-ruby.

thinkingserious avatar thinkingserious commented on July 18, 2024

Thank you @davidsavoya,

We will take a look.

Also, could you show us the code for the header_builder?

from sendgrid-ruby.

itsmatthu avatar itsmatthu commented on July 18, 2024

my code is :

@mail = SendGrid::Mail.new do |m|
      m.to = @email
      m.from = "<#{ENV['SMTP_DEFAULT_FROM_EMAIL']}>"
      m.subject = (I18n.t 'invite_project_user.welcome_title', project_name: @project_name)
      m.bcc = ENV['BCC_MAIL'].to_s if @info['first']
      m.html = template.result(binding)
end

It works for me.

from sendgrid-ruby.

itsmatthu avatar itsmatthu commented on July 18, 2024

BTW, I am on v1.1.6, too.
The mail function works fine these days.
And I can't tell what's wrong with your code, sorry.
I suggest you debug into SendGrid::Mail.new when you call it, to see what just happens. @davidsavoya

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

When I build the mail object, I can see that '@bcc' gets built to be the string I want and when I call send on an the sendgrid client, the mail that I call it with has '@bcc' with the string email address I want.

Is there anything on the response back that would give any clues?

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

Is there anything in my account settings with SendGrid that needs to be adjusted?

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

Playing around with this, I can remove my 'to' assignment from the mail class since I pass my recipients to

 mail.smtpapi = header_builder.build_header(recipients)

which is building a Smtpapi::Header. It seems that who I am sending mail to is a result of who I add to the 'to' of the Smtpapi::Header. I don't see a way to add a bcc or cc to this class.

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

Hey guys, I was able to get this working by adding a bcc filter on the header. I appreciate y'all looking into this.

      header.add_filter("bcc", "enable", 1) # necessary for each time the template engine is used
      header.add_filter("bcc", "email", "[email protected]")

from sendgrid-ruby.

davidsavoya avatar davidsavoya commented on July 18, 2024

Do you think

def smtpapi_json
      if !template.nil? && template.is_a?(Template)
        template.add_to_smtpapi(smtpapi)
      end

      smtpapi.to_json
    end

In SendGrid::Mail could do something similar with the bcc by adding to the smtpapi json? If so, I would be happy to give it a go at home. LMK or feel free to close

from sendgrid-ruby.

itsmatthu avatar itsmatthu commented on July 18, 2024

@davidsavoya glad you find the work around.
for your last question, In SendGrid::Mail could do something similar with the bcc by adding to the smtpapi json? I digged into this before (just because my project only used stmpapi before and PM got the bcc requirement, OMG ). it seems there is no way to make it right with using stmpapi.

from sendgrid-ruby.

thinkingserious avatar thinkingserious commented on July 18, 2024

Hello @matt-hu,

The new version of this library has come out of beta yesterday. It uses our new v3 /mail/send endpoint, which includes the SMTPAPI functionality without an external dependency.

from sendgrid-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.