You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails应用中Sendgrid BCC功能将停用,当前如何使用该功能?

How to Use BCC with SendGrid in Your Rails App (Until June 22, 2020)

Hey there,

Based on the notification you got from SendGrid, here's a clear breakdown of what you can do to keep using BCC until its full removal on June 22, 2020:

Current BCC Availability Status

SendGrid has disabled BCC access via their UI, but the feature is still usable only through API calls until the cutoff date. You'll need to adjust your Rails app's email-sending logic to leverage either the SendGrid API directly or ensure your existing Action Mailer setup works with their SMTP endpoint correctly.

Option 1: Stick with Action Mailer + SendGrid SMTP

If you're already using Action Mailer with SendGrid as your SMTP provider, you can keep using BCC just like you always have—SMTP supports BCC, and SendGrid will honor this until the cutoff date.

  1. First, double-check your SMTP settings in config/environments/production.rb (or your target environment):
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: 'smtp.sendgrid.net',
  port: 587,
  domain: 'your-app-domain.com',
  user_name: 'apikey',
  password: ENV['SENDGRID_API_KEY'],
  authentication: :plain,
  enable_starttls_auto: true
}
  1. In your mailer class, add the bcc parameter to your mail call as usual:
class UpdateMailer < ApplicationMailer
  def critical_alert
    mail(
      to: 'primary-user@example.com',
      bcc: 'admin-alerts@example.com', # This will work via SMTP
      subject: 'Urgent System Update'
    )
  end
end

Option 2: Use the SendGrid Ruby API Client Directly

If you want more control over your email sending, you can use SendGrid's official Ruby API client to build and send emails with BCC recipients.

  1. Install the sendgrid-ruby gem if you haven't already:
gem install sendgrid-ruby
# Or add to your Gemfile and run bundle install
gem 'sendgrid-ruby', require: 'sendgrid'
  1. Build and send your email with a BCC recipient using the API:
require 'sendgrid-ruby'
include SendGrid

# Initialize the API client with your key
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

# Define email components
from_email = Email.new(email: 'notifications@your-app.com')
to_email = Email.new(email: 'user@example.com')
bcc_email = Email.new(email: 'compliance@your-app.com')
subject = 'Monthly Compliance Update'
content = Content.new(type: 'text/plain', value: 'This update includes a BCC to our compliance team via SendGrid API.')

# Assemble the mail object and attach the BCC recipient
mail = Mail.new(from_email, subject, to_email, content)
mail.bcc = bcc_email

# Send the email
response = sg.client.mail._('send').post(request_body: mail.to_json)

# Optional: Verify the send status
puts "Send status code: #{response.status_code}"

Critical Reminder

Don't forget to plan for the June 22, 2020 cutoff date. After that, SendGrid will fully remove the BCC feature. For long-term alternatives, consider:

  • Sending separate email copies to your "BCC" recipients directly from your Rails app
  • Using SendGrid's list management or batch sending features to reach multiple recipients without relying on BCC
  • Building custom logic in your app to handle hidden recipient needs

内容的提问来源于stack exchange,提问作者webster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:32:27