0

我将 pdf 文档存储在数据库中,并使用以下代码行通过电子邮件发送:+

def invoice(payment)
  @payment = payment
  @user = payment.subscriber or raise(ActiveRecord::RecordNotFound)
  @subscription = payment.subscription or raise(ActiveRecord::RecordNotFound)
  attachments[@payment.invoice_doc_name] = {
    :mime_type => 'application/pdf',
    :encoding => 'base64',
    :content => @payment.invoice_pdf
  } 
  mail to: @user.email
end

这在我在 Heroku Cedar 上的开发、测试和暂存环境中运行良好,就像生产一样。PDF是正确的,我可以在用户界面中下载它。生产配置为:

Railsapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# Code is not reloaded between requests
config.cache_classes = true

# Full error reports are disabled and caching is turned on
config.consider_all_requests_local             = false
config.action_controller.perform_caching = true

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Specify the default JavaScript compressor
config.assets.js_compressor    = :uglifier

# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = nil

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

# See everything in the log (default is :info)
# config.log_level = :debug

# Use a different logger for distributed setups
config.logger = Logger.new($stdout)

# Use a different cache store in production
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

# Enable threaded mode
# config.threadsafe!

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify

# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.default_url_options = {
    :host => 'www.****.com',
    :protocol => 'https'
} 
config.action_mailer.smtp_settings = {
    :address => 'smtp.gmail.com',
    :enable_startls_auto => true,
    :port => 587,
    :authentication => :plain,
    :user_name => '***',
    :password => '***'
}
end
4

0 回答 0