感谢gigix推荐这么实用的插件:http://www.iteye.com/topic/36627#296988记录下来
因为在项目中用到gmail,而gmail的smtp又是带ssl认证的,Rails的Action Mailer是实现不了的。如果你也碰到这样的问题,或者也打算用gmail smtp,这个插件也许是你想要的。
0:前提
还没了解ActionMailer?那就先看看这里
ActionMailer:http://wiki.rubyonrails.org/rails/pages/ActionMailer
1:安装
ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls
2:使用
和你平时一样,不需要额外做什么
3:原理
我们来看下它的代码,很简单,就一个文件,覆盖了ActionMailer的do_start方法
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
check_response(critical { recv_response() })
do_helo(helodomain)
raise 'openssl library not installed' unless defined?(OpenSSL)
starttls
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
do_helo(helodomain)
authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not @socket.closed?
@socket = nil
end
end
...
end
分享到:
相关推荐
**Rails 常用插件简介 - CRUD Generator 2** 在Ruby on Rails框架中,开发过程中经常需要创建、读取、更新和删除(CRUD)数据。为了提高开发效率,开发者通常会使用各种插件来自动化这个过程。CRUD Generator 2就是...
标题提到的"用于过滤英文脏话的 Rails 插件 gem"正是为了解决这个问题。这个插件允许开发者通过简单的配置,对输入的文本进行检查和替换,确保网站内容的清洁度和专业性。 这个插件名为`profanity_filter`,它是一...
介绍插件,用于对记录进行排序(使用 gem)安装要启用rails_admin_acts_as_list,请将以下内容添加到您的Gemfile : gem 'rails_admin_acts_as_list'gem 'rails_admin' 重要提示: rails_admin_acts_as_list之前必须...
Rails_3_Cheat_Sheets.pdf
本资料“RestFul_Rails_Dev_pdf_v_0.1.zip”包含了《RESTful Rails Development》的翻译版,将深入探讨如何在Rails中实现RESTful的设计模式。 首先,RESTful设计的核心概念是资源(Resources)。在Rails中,资源...
Rails 管理员成为用户 ... rails_admin_become_user必须在rails_admin之后rails_admin才能正常工作。 在您的config/initializers/rails_admin.rb初始化程序中添加配置: RailsAdmin . config do | config |
安装将此行添加到您的应用程序的Gemfile中: gem 'ar_mailer_aws'然后执行: $ bundle运行发电机: $ rails g ar_mailer_aws BatchEmail运行迁移: $ rake db:migrate或将其自己安装为: $ gem install ar_mailer_...
Awesome Rails Gem 是一个广泛收录了Rails开发中常用、实用、有趣的Gem的列表,旨在帮助开发者提高开发效率和代码质量。这个中文版的Awesome Rails Gem列表,为国内开发者提供了一个方便的参考资源,使他们能够更好...
ResqueMailer 一个gem插件,允许ActionMailer准备的消息异步传递。 假设您正在使用进行后台作业。 请注意,Resque :: Mailer的最新(2.0+)版本仅适用于Rails 3.x或更高版本。 对于与Rails 2兼容的版本,在Gemfile中...
14. **邮件发送(Action Mailer)**:Rails内置了Action Mailer用于发送电子邮件,书中可能会涉及邮件模板、配置和测试。 通过阅读《Rails Recipes with Source Code》,开发者可以深入理解Rails的各个层面,并学会...
gem 'action_mailer_matchers' , '~> 1.0' end 然后执行: $ bundle install 或自己安装为: $ gem install action_mailer_matchers 通过要求将ActionMailerMatchers包括在您的RSpec配置中,并将其包括在您的...
gem 'rails_admin_image_manager' 跑步 $ bundle install 安装RailsAdmin_ImageManager $ rails generate rails_admin_image_manager:install 将上传文件路径添加到您的.gitignore文件中 /public/rails_admin_...
安装可以使用内置的Rails插件脚本来完成插件的安装。 从Rails应用程序的根目录发出以下命令: $ ./script/rails plugin install git://github.com/anandagrawal84/resque_failed_job_mailer.git或将其添加到您的...
Agile Web Development with Rails 1-14节_ppt(老师发的修正版)
gem 'rails_admin_content_builder' 运行生成器并进行迁移 rails g rails_admin_content_builder rake db:migrate 在app / assets / application.scss中添加样式 * = require rails_admin_content_builder 用法 ...
在Ruby on Rails中,插件通常是一组自包含的代码,可以扩展框架的功能或者提供新的行为。它们可以包括模型、控制器、视图、迁移、甚至是Rake任务等。在这个案例中,“login_engine”可能是包含了用户登录所需的所有...
在Rails中实现HTTP基本认证,开发者可以在Controller的before_action中添加代码来检查请求头中的认证信息。 Restful-Authentication则是一个更全面的解决方案,它包含了注册、登录、登出、密码重置等功能。该插件...