Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
looyolo
scrapy
提交
6585c1a2
S
scrapy
项目概览
looyolo
/
scrapy
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrapy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6585c1a2
编写于
8月 22, 2010
作者:
P
Pablo Hoffman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removed (somewhat hacky) MAIL_DEBUG setting
上级
e189861b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
8 addition
and
25 deletion
+8
-25
docs/topics/email.rst
docs/topics/email.rst
+0
-12
scrapy/mail.py
scrapy/mail.py
+3
-2
scrapy/tests/test_mail.py
scrapy/tests/test_mail.py
+5
-11
未找到文件。
docs/topics/email.rst
浏览文件 @
6585c1a2
...
...
@@ -58,9 +58,6 @@ uses `Twisted non-blocking IO`_, like the rest of the framework.
Send email to the given recipients. Emits the :signal:`mail_sent` signal.
If :setting:`MAIL_DEBUG` is enabled the :signal:`mail_sent` signal will
be emmited and no actual email will be sent.
:param to: the e-mail recipients
:type to: list
...
...
@@ -136,15 +133,6 @@ Default: ``None``
Password to use for SMTP authentication, along with :setting:`MAIL_USER`.
.. setting:: MAIL_DEBUG
MAIL_DEBUG
----------
Default: ``False``
Whether to enable the debugging mode.
Mail signals
============
...
...
scrapy/mail.py
浏览文件 @
6585c1a2
...
...
@@ -28,12 +28,13 @@ mail_sent = object()
class
MailSender
(
object
):
def
__init__
(
self
,
smtphost
=
None
,
mailfrom
=
None
,
smtpuser
=
None
,
smtppass
=
None
,
\
smtpport
=
None
):
smtpport
=
None
,
debug
=
False
):
self
.
smtphost
=
smtphost
or
settings
[
'MAIL_HOST'
]
self
.
smtpport
=
smtpport
or
settings
.
getint
(
'MAIL_PORT'
)
self
.
smtpuser
=
smtpuser
or
settings
[
'MAIL_USER'
]
self
.
smtppass
=
smtppass
or
settings
[
'MAIL_PASS'
]
self
.
mailfrom
=
mailfrom
or
settings
[
'MAIL_FROM'
]
self
.
debug
=
debug
if
not
self
.
smtphost
or
not
self
.
mailfrom
:
raise
NotConfigured
(
"MAIL_HOST and MAIL_FROM settings are required"
)
...
...
@@ -67,7 +68,7 @@ class MailSender(object):
send_catch_log
(
signal
=
mail_sent
,
to
=
to
,
subject
=
subject
,
body
=
body
,
cc
=
cc
,
attach
=
attachs
,
msg
=
msg
)
if
se
ttings
.
getbool
(
'MAIL_DEBUG'
)
:
if
se
lf
.
debug
:
log
.
msg
(
'Debug mail sent OK: To=%s Cc=%s Subject="%s" Attachs=%d'
%
\
(
to
,
cc
,
subject
,
len
(
attachs
)),
level
=
log
.
DEBUG
)
return
...
...
scrapy/tests/test_mail.py
浏览文件 @
6585c1a2
...
...
@@ -3,22 +3,20 @@ import unittest
from
scrapy.xlib.pydispatch
import
dispatcher
from
scrapy.conf
import
settings
from
scrapy.mail
import
MailSender
,
mail_sent
class
MailSenderTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
settings
.
disabled
=
False
settings
.
overrides
[
'MAIL_DEBUG'
]
=
True
self
.
catched_msg
=
None
dispatcher
.
connect
(
self
.
_catch_mail_sent
,
signal
=
mail_sent
)
def
tearDown
(
self
):
dispatcher
.
disconnect
(
self
.
_catch_mail_sent
,
signal
=
mail_sent
)
def
test_send
(
self
):
mailsender
=
MailSender
()
mailsender
=
MailSender
(
debug
=
True
)
mailsender
.
send
(
to
=
[
'test@scrapy.org'
],
subject
=
'subject'
,
body
=
'body'
)
assert
self
.
catched_msg
...
...
@@ -38,7 +36,7 @@ class MailSenderTest(unittest.TestCase):
attach
.
seek
(
0
)
attachs
=
[(
'attachment'
,
'text/plain'
,
attach
)]
mailsender
=
MailSender
()
mailsender
=
MailSender
(
debug
=
True
)
mailsender
.
send
(
to
=
[
'test@scrapy.org'
],
subject
=
'subject'
,
body
=
'body'
,
attachs
=
attachs
)
...
...
@@ -59,10 +57,6 @@ class MailSenderTest(unittest.TestCase):
self
.
assertEqual
(
text
.
get_payload
(
decode
=
True
),
'body'
)
self
.
assertEqual
(
attach
.
get_payload
(
decode
=
True
),
'content'
)
def
tearDown
(
self
):
del
settings
.
overrides
[
'MAIL_DEBUG'
]
settings
.
disabled
=
True
def
_catch_mail_sent
(
self
,
**
kwargs
):
self
.
catched_msg
=
dict
(
**
kwargs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录