我已经尝试了所有我能想到的东西,以便通过Rails 4.1.6(本地开发)发送电子邮件,但没有任何工作。使用Postmark我在development.rb和application.rb中有以下内容:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => API_KEY }
config.action_mailer.perform_deliveries = true
对于GMAIL我尝试过:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'my_email',
password: 'my_password',
authentication: 'plain',
enable_starttls_auto: true }
My Mailer类看起来像这样:
class BusinessMailer < ActionMailer::Base
default from: "my_email@email.com"
def claim_business business
mail(
:subject => 'hello',
:to => 'myemail@email.com',
:from => 'myemail@email.com',
:html_body => '<strong>Hello John Doe<strong>',
:track_opens => 'true'
)
end
end
最后我通过以下方式发送电子邮件:BusinessMailer.claim_business @business
当我触发claim_business
方法时,我在控制台中看到BusinessMailer#claim_business: processed outbound mail in 14.1ms
没有错误消息。谁能告诉我我在这里缺少什么?
答案 0 :(得分:17)
您最近缺少deliver
方法以最终发送电子邮件。尝试:
BusinessMailer.claim_business(@business).deliver