【发布时间】:2017-12-05 23:10:23
【问题描述】:
我正在尝试在将简历文件上传到职位发布时发送通知电子邮件。我正在尝试在生产中使用 Gmail SMTP,但在 Heroku 日志中不断收到这些错误消息:
Completed 500 Internal Server Error in 505ms (ActiveRecord: 11.3ms)
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
Development.rb 中一切正常,但我不知道为什么它在生产中不起作用。
这是我的控制器:请参阅“创建”
class ResumesController < ApplicationController
helper_method :count
def new
@resume = Resume.new
@post = Post.find(params[:post_id])
end
def create
@resume = Resume.new(resume_params)
@resume.user_id = current_user.id
@resume.post_id = params[:post_id]
if @resume.save
ResumeMailer.resume_received(@resume).deliver_now
current_user.credits = current_user.credits + 1
current_user.save!
flash[:success] = "Congratulations! Your Candidate has been submitted and 1 Credit has been added to your account!"
redirect_to :root
end
end
def show
resume = Resume.find(params[:id])
if current_user.unlocks.where(resume_id: resume.id).length > 0
send_file resume.document.path.split('?')[0], :filename => resume.document_file_name, :type => ["application/pdf", "application/doc", "application/docx"], :disposition => "attachment"
elsif current_user.credits > 0
current_user.credits = current_user.credits - 1
current_user.save!
Unlock.create(user_id: current_user.id, resume_id: resume.id)
send_file resume.document.path.split('?')[0], :filename => resume.document_file_name, :type => ["application/pdf", "application/doc", "application/docx"], :disposition => "attachment"
else
flash[:success] = "Your Credit balance is zero. Submit more resumes for more Credits!"
redirect_to inbox_path
end
end
def inbox
@resumes = current_user.incoming_resumes.order("created_at DESC")
end
def destroy
@resume = Resume.find(params[:id])
@resume.destroy
flash[:success] = "Your Resume has been successfully deleted!"
redirect_to inbox_path
end
def count
current_user.resumes.count
end
private
def resume_params
params.require(:resume).permit(:document)
end
end
这是我的邮件:
class ResumeMailer < ApplicationMailer
default from: "MYEMAIL@gmail.com"
def resume_received(resume)
@resume = resume
@post = @resume.post
mail to: @post.user.email,
subject: "You have received a new Candidate for the #{@post.title} posting!"
end
end
这是我的 Development.rb SMTP:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.active_record.raise_in_transactional_callbacks = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
这是我的 Production.rb SMTP:
config.action_mailer.default_url_options = { host: 'MYSITE.herokuapp.com', protocol: 'http' }
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
openssl_verify_mode: 'none'
}
}
此设置在开发中运行良好,我也已经进入 GMAIL 设置以允许访问不太安全的应用程序。任何能指引我正确方向的帮助或资源将不胜感激。
【问题讨论】:
标签: ruby-on-rails email heroku smtp gmail