Heroku在邮件/发送网格后无法安装我的应用程序。我得到的错误是:
远程:卸下链轮导轨 (3.0.4) 远程:-----
邮寄功能是在对他们的文章发表评论时向管理员发送电子邮件,并在文章发布时向“关注者”发送电子邮件。
class CommentMailer < ActionMailer::Base
def comment_created(评论,文章) @comment = 评论 @article = 文章
mail( to: @article.user.email ,
from:'no_reply@gmail.com' ,
subject:'A comment on your post.')
结束 结束
class ArticleMailer < ActionMailer::Base
def article_created(follower, article) @article = article follower.each do |f|邮件至:f.email,from:'no_reply@gmail.com',主题:“已创建文章”结束结束
<h3> Stay up tp date with my new articles </h3>
<p> You will be sent an email whenever a new article was posted </p>
<%= form_for @follower do |f| %>
<%= f.label :name, "Your Name:" %>
<%= f.text_field :name %>
<br>
<%= f.label :email %>
<%= f.text_field :email %>
<br>
<%= f.submit('Follow me') %>
<% end %>
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = { host: "https://personal-blog22.herokuapp.com " }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true }
# For better error to work on Vagrant VM
BetterErrors::Middleware.allow_ip! "0.0.0.0/0"
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.consider_all_requests_local
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_controller.perform_caching = false
end
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module PersonalBlog
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "ruby.blog100.com",
user_name: "XXXXXXgmail.com",
password: "XXXXX",
authentication: :plain,
enable_starttls_auto: true
}
end
end
尝试在配置/环境/生产中进行更改.rb
改变:
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
自
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
因为邮件
没有在您的 heroku 环境中初始化。在本地环境中,它可能会在本地 Gem 或包中初始化。
您更新的代码似乎在文件中没有结尾。尝试将以下代码复制并粘贴到您的 production.rb 文件中。它会为你工作。
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = { host: "https://personal-blog22.herokuapp.com " }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end