我正在尝试使用rails 4中的Action邮件发送通知邮件,但它无法正常工作。解决了很多错误后,我能够发送邮件,并且没有错误显示在控制台中但是没有收到邮件。这一直对我有用,但我不知道现在怎么回事。这是控制台中的输出。
AdminMailer#subscription_added: processed outbound mail in 202.7ms
Sent mail to receiver@gmail.com (9.8ms)
Date: Sat, 28 Nov 2015 21:25:52 +0530
To: receiver@gmail.com
Message-ID: <5659ce8829e54_2b0563310f2520dc@ubuntu.mail>
Subject: Subscription addded
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!--XRAY START 8 /home/yogesh/Desktop/new/munam/app/views/layouts/mailer.html.haml-->
<hmtl>
<body>
<!--XRAY START 7 /home/yogesh/Desktop/new/munam/app/views/admin_mailer/subscription_added.html.haml-->
name of receiver
Email receiver@gmail.com
<!--XRAY END 7-->
</body>
</hmtl>
<!--XRAY END 8-->
Completed 302 Found in 320ms (ActiveRecord: 70.3ms)
这是我的代码
在我的development.rb
中Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { :host => "localhost:3000" }
# Automatically inject JavaScript needed for LiveReload
# config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'localhost:3000',
user_name: 'mymail@gmail.com',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true }
end
我的触发邮件的代码
AdminMailer.subscription_added(@subscription).deliver_now
我的管理员邮件
class AdminMailer < ApplicationMailer
def subscription_added(subscription)
@subscription = subscription
begin
mail(:to => "sender@gmail.com", :subject => "Subscription addded")
rescue Exception => e
end
end
end
如果有人告诉我哪里出错或者我还需要做多少工作,我真的很感激。非常感谢。
答案 0 :(得分:1)
您在尝试发送电子邮件时隐藏了可能发生的任何错误,请使用以下行:
config.action_mailer.raise_delivery_errors = false
将其更改为true
,重新启动服务器,如果您尝试发送邮件,则会收到错误。
在开发过程中,我建议不要使用真正的实时邮件服务器 - 我建议使用类似Mailcatcher(http://mailcatcher.me/)的内容
答案 1 :(得分:1)
尝试使用development.rb文件中的以下代码引发运行时错误。
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true