sendgrid-rails
sendgrid-rails copied to clipboard
Sendgrid BCC/CC not working correctly
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
Isn't the behavior you've described is right? Maybe share an example with expected and actual results, please?
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.
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.
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```
@zeeshangulzar I see. It's a design issue. Take a look: https://github.com/paveltyk/sendgrid-rails/blob/9dc40ff13216fad8a78b489acb0fa6a2805cba77/lib/send_grid/mail_interceptor.rb#L6
Unfortunately, I do not have time to fix this now. I would highly appreciate a PR to fix this issue, though.
Thanks @paveltyk I will work on it in some free time.
Is there any work-around for this one?