Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sendgrid BCC/CC not working correctly #34

Open
zeeshangulzar opened this issue Aug 5, 2019 · 5 comments
Open

Sendgrid BCC/CC not working correctly #34

zeeshangulzar opened this issue Aug 5, 2019 · 5 comments

Comments

@zeeshangulzar
Copy link

zeeshangulzar commented Aug 5, 2019

I am using Sendgrid in my Rails application, when I add emails in TO and BCC/CC, then after sending the email through my application, TO email is working fine and I got the email, but when I logged in with the same BCC/CC email in my account(e.g. Gmail), then there is no TO email details and my BCC/CC email shifted in the TO field, so that my email (that means BCC/CC email) is showing into the TO field.

As per the default process, for the BCC email user, TO email details should be in the TO field and my email (BCC email) should show into the BCC field section. But it is not working like that.

Please let me know, how can I achieve this process, so that based on the default functionality, my BCC email will display into the BCC email field instead of TO field.

Following are my config in /initialzers/mail.rb

ActionMailer::Base.register_observer(TrackedEmailEvents)

ActionMailer::Base.smtp_settings = {
  address: 'smtp.sendgrid.net',
  port: 587,
  domain: 'syncta.com',
  authentication: :plain,
  enable_starttls_auto: true,
  user_name: ENV['SENDGRID_USERNAME'],
  password: ENV['SENDGRID_SECRET']
}

SendGrid.configure do |config|
  config.dummy_recipient = '[email protected]'
end

If i remove intercept it will work as expected, but i need intercepter as I m using X-SMTPAPI' header in observer

I also tried to move my config into config/environment as mentioned here but no success.
Ruby Version: ruby 2.5.1
Rails Version: 5.1.6

@paveltyk
Copy link
Owner

paveltyk commented Aug 5, 2019

Isn't the behavior you've described is right? Maybe share an example with expected and actual results, please?

@zeeshangulzar
Copy link
Author

zeeshangulzar commented Aug 6, 2019

I am sharing the cc case. I am sending email at following
to: [email protected]
cc [email protected]

For the cc email address ([email protected]), following is the details i received at gmail.
1- Current CC
to & cc fields are same which is incorrect. cc user should be able to see the to address.
Here is the expected behaviour for cc.
3- Expected CC
to field should be populated with [email protected]

I got the expected behaviour by removing the ActionMailer::Base.register_interceptor(SendGrid::MailInterceptor) line from mail initializer.
But we need to add interceptor in our code to set X-SMTPAPI header used in webhooks
https://github.com/paveltyk/sendgrid-rails/blob/master/lib/send_grid/mail_interceptor.rb#L8

Here is the sample code used.

    sample = Sample.find(id)
    @body = 'sample text for body'
    company = sample.company
    mail(subject: 'Sample Subject',
         to: ['[email protected]'],
         **cc_or_bcc(company),
         from: '[email protected]',
         reply_to: '[email protected]') do |format|
      format.html { render 'shared/emails/body' }
    end
  end

  def cc_or_bcc(company)
    { (company.to_cc? ? :cc : :bcc) => '[email protected]' }
  end```

@paveltyk
Copy link
Owner

paveltyk commented Aug 6, 2019

@zeeshangulzar I see. It's a design issue. Take a look:

sendgrid_header.add_recipients(mail.cc)

Unfortunately, I do not have time to fix this now. I would highly appreciate a PR to fix this issue, though.

@zeeshangulzar
Copy link
Author

Thanks @paveltyk I will work on it in some free time.

@PeaceS
Copy link

PeaceS commented Mar 16, 2021

Is there any work-around for this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants