Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8fc8763f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8fc8763f
编写于
8月 20, 2012
作者:
A
Aditya Sanghi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow delivery method options to be set per mail instance
上级
27acd1e0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
3 deletion
+58
-3
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+16
-0
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+1
-1
actionmailer/lib/action_mailer/delivery_methods.rb
actionmailer/lib/action_mailer/delivery_methods.rb
+2
-2
actionmailer/test/delivery_methods_test.rb
actionmailer/test/delivery_methods_test.rb
+39
-0
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
8fc8763f
## Rails 4.0.0 (unreleased) ##
*
Allow delivery method options to be set per mail instance
*Aditya Sanghi*
If your smtp delivery settings are dynamic,
you can now override settings per mail instance for e.g.
def my_mailer(user,company)
mail to: customer.email, subject: "Welcome!",
delivery_method_options: {user_name: company.smtp_user,
password: company.smtp_password}
end
This will ensure that your default SMTP settings will be overridden
by the company specific ones. You only have to override the settings
that are dynamic and leave the static setting in your environment
configuration file (e.g. config/environments/production.rb)
*
Allow to set default Action Mailer options via
`config.action_mailer.default_options=`
*Robert Pankowecki*
*
Raise an
`ActionView::MissingTemplate`
exception when no implicit template could be found.
*Damien Mathieu*
...
...
actionmailer/lib/action_mailer/base.rb
浏览文件 @
8fc8763f
...
...
@@ -683,7 +683,7 @@ def mail(headers={}, &block)
m
.
charset
=
charset
=
headers
[
:charset
]
# Set configure delivery behavior
wrap_delivery_behavior!
(
headers
.
delete
(
:delivery_method
))
wrap_delivery_behavior!
(
headers
.
delete
(
:delivery_method
)
,
headers
.
delete
(
:delivery_method_options
)
)
# Assign all headers except parts_order, content_type and body
assignable
=
headers
.
except
(
:parts_order
,
:content_type
,
:body
,
:template_name
,
:template_path
)
...
...
actionmailer/lib/action_mailer/delivery_methods.rb
浏览文件 @
8fc8763f
...
...
@@ -57,7 +57,7 @@ def add_delivery_method(symbol, klass, default_options={})
self
.
delivery_methods
=
delivery_methods
.
merge
(
symbol
.
to_sym
=>
klass
).
freeze
end
def
wrap_delivery_behavior
(
mail
,
method
=
nil
)
#:nodoc:
def
wrap_delivery_behavior
(
mail
,
method
=
nil
,
options
=
nil
)
#:nodoc:
method
||=
self
.
delivery_method
mail
.
delivery_handler
=
self
...
...
@@ -66,7 +66,7 @@ def wrap_delivery_behavior(mail, method=nil) #:nodoc:
raise
"Delivery method cannot be nil"
when
Symbol
if
klass
=
delivery_methods
[
method
]
mail
.
delivery_method
(
klass
,
send
(
:"
#{
method
}
_settings"
))
mail
.
delivery_method
(
klass
,
(
send
(
:"
#{
method
}
_settings"
)
||
{}).
merge!
(
options
||
{}
))
else
raise
"Invalid delivery method
#{
method
.
inspect
}
"
end
...
...
actionmailer/test/delivery_methods_test.rb
浏览文件 @
8fc8763f
...
...
@@ -4,6 +4,13 @@
class
MyCustomDelivery
end
class
MyOptionedDelivery
attr_reader
:options
def
initialize
(
options
)
@options
=
options
end
end
class
BogusDelivery
def
initialize
(
*
)
end
...
...
@@ -115,6 +122,38 @@ def teardown
assert_instance_of
Mail
::
TestMailer
,
email
.
delivery_method
end
test
"delivery method options default to class level options"
do
default_options
=
{
a:
"b"
}
ActionMailer
::
Base
.
add_delivery_method
:optioned
,
MyOptionedDelivery
,
default_options
mail_instance
=
DeliveryMailer
.
welcome
(
:delivery_method
=>
:optioned
)
assert_equal
default_options
,
mail_instance
.
delivery_method
.
options
end
test
"delivery method options can be overridden per mail instance"
do
default_options
=
{
a:
"b"
}
ActionMailer
::
Base
.
add_delivery_method
:optioned
,
MyOptionedDelivery
,
default_options
overridden_options
=
{
a:
"a"
}
mail_instance
=
DeliveryMailer
.
welcome
(
:delivery_method
=>
:optioned
,
:delivery_method_options
=>
overridden_options
)
assert_equal
overridden_options
,
mail_instance
.
delivery_method
.
options
end
test
"default delivery options can be overridden per mail instance"
do
settings
=
{
:address
=>
"localhost"
,
:port
=>
25
,
:domain
=>
'localhost.localdomain'
,
:user_name
=>
nil
,
:password
=>
nil
,
:authentication
=>
nil
,
:enable_starttls_auto
=>
true
}
assert_equal
settings
,
ActionMailer
::
Base
.
smtp_settings
overridden_options
=
{
user_name:
"overridden"
,
:password
=>
"somethingobtuse"
}
mail_instance
=
DeliveryMailer
.
welcome
(
:delivery_method_options
=>
overridden_options
)
delivery_method_instance
=
mail_instance
.
delivery_method
assert_equal
"overridden"
,
delivery_method_instance
.
settings
[
:user_name
]
assert_equal
"somethingobtuse"
,
delivery_method_instance
.
settings
[
:password
]
assert_equal
delivery_method_instance
.
settings
.
merge
(
overridden_options
),
delivery_method_instance
.
settings
end
test
"non registered delivery methods raises errors"
do
DeliveryMailer
.
delivery_method
=
:unknown
assert_raise
RuntimeError
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录