Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
e7b4bd48
Kaydet (Commit)
e7b4bd48
authored
Haz 16, 2015
tarafından
Rolo
Kaydeden (comit)
Tim Graham
Haz 22, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24970 -- Added --managers and --admins options to the sendtestemail management command.
üst
1c90a3dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
13 deletions
+89
-13
sendtestemail.py
django/core/management/commands/sendtestemail.py
+18
-5
django-admin.txt
docs/ref/django-admin.txt
+12
-0
test_sendtestemail.py
tests/mail/test_sendtestemail.py
+59
-8
No files found.
django/core/management/commands/sendtestemail.py
Dosyayı görüntüle @
e7b4bd48
import
datetime
import
socket
from
django.core.mail
import
send_mail
from
django.core.mail
import
mail_admins
,
mail_managers
,
send_mail
from
django.core.management.base
import
BaseCommand
from
django.utils
import
timezone
class
Command
(
BaseCommand
):
help
=
"Sends a test email to the email addresses specified as arguments."
missing_args_message
=
"You must specify some email recipients, or pass the --managers or --admin options."
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'email'
,
nargs
=
'+'
,
help
=
'One or more email addresses to send the test mail to.'
)
parser
.
add_argument
(
'email'
,
nargs
=
'*'
,
help
=
'One or more email addresses to send a test email to.'
)
parser
.
add_argument
(
'--managers'
,
action
=
'store_true'
,
dest
=
'managers'
,
default
=
False
,
help
=
'Send a test email to the addresses specified in settings.MANAGERS.'
)
parser
.
add_argument
(
'--admins'
,
action
=
'store_true'
,
dest
=
'admins'
,
default
=
False
,
help
=
'Send a test email to the addresses specified in settings.ADMINS.'
)
def
handle
(
self
,
*
args
,
**
kwargs
):
subject
=
'Test email from
%
s on
%
s'
%
(
socket
.
gethostname
(),
timezone
.
now
())
send_mail
(
subject
=
'Test email from
%
s on
%
s'
%
(
socket
.
gethostname
(),
datetime
.
datetime
.
now
())
,
subject
=
subject
,
message
=
"If you
\'
re reading this, it was successful."
,
from_email
=
None
,
recipient_list
=
kwargs
[
'email'
],
)
if
kwargs
[
'managers'
]:
mail_managers
(
subject
,
"This email was sent to the site managers."
)
if
kwargs
[
'admins'
]:
mail_admins
(
subject
,
"This email was sent to the site admins."
)
docs/ref/django-admin.txt
Dosyayı görüntüle @
e7b4bd48
...
...
@@ -902,6 +902,18 @@ recipient(s) specified. For example::
django-admin sendtestemail foo@example.com bar@example.com
.. django-admin-option:: --managers
Use the ``--managers`` option to mail the email addresses specified in
:setting:`MANAGERS` using :meth:`~django.core.mail.mail_managers()`.
.. django-admin-option:: --admins
Use the ``--admins`` option to mail the email addresses specified in
:setting:`ADMINS` using :meth:`~django.core.mail.mail_admins()`.
Note that you may use any combination of these options together.
shell
-----
...
...
tests/mail/test_sendtestemail.py
Dosyayı görüntüle @
e7b4bd48
...
...
@@ -2,32 +2,83 @@ from __future__ import unicode_literals
from
django.core
import
mail
from
django.core.management
import
call_command
from
django.test
import
SimpleTestCase
from
django.test
import
SimpleTestCase
,
override_settings
@override_settings
(
ADMINS
=
((
'Admin'
,
'admin@example.com'
),
(
'Admin and Manager'
,
'admin_and_manager@example.com'
)),
MANAGERS
=
((
'Manager'
,
'manager@example.com'
),
(
'Admin and Manager'
,
'admin_and_manager@example.com'
)),
)
class
SendTestEmailManagementCommand
(
SimpleTestCase
):
"""
Test the sending of a test email using the `sendtestemail` command.
"""
def
test_s
end_test_email
(
self
):
def
test_s
ingle_receiver
(
self
):
"""
The mail is sent with the correct subject and recipient.
"""
recipient
=
"joe@example.com"
call_command
(
"sendtestemail"
,
recipient
)
recipient
=
'joe@example.com'
call_command
(
'sendtestemail'
,
recipient
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
mail_message
=
mail
.
outbox
[
0
]
self
.
assertEqual
(
mail_message
.
subject
[
0
:
15
],
'Test email from'
)
self
.
assertEqual
(
mail_message
.
recipients
(),
[
recipient
])
def
test_
send_test_email_with_multiple_addresse
s
(
self
):
def
test_
multiple_receiver
s
(
self
):
"""
The mail may be sent with multiple recipients.
"""
recipients
=
[
"joe@example.com"
,
"jane@example.com"
]
call_command
(
"sendtestemail"
,
recipients
[
0
],
recipients
[
1
])
recipients
=
[
'joe@example.com'
,
'jane@example.com'
]
call_command
(
'sendtestemail'
,
recipients
[
0
],
recipients
[
1
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
mail_message
=
mail
.
outbox
[
0
]
self
.
assertEqual
(
mail_message
.
subject
[
0
:
15
],
'Test email from'
)
self
.
assertEqual
(
mail_message
.
recipients
(),
recipients
)
self
.
assertEqual
(
sorted
(
mail_message
.
recipients
()),
[
'jane@example.com'
,
'joe@example.com'
,
])
def
test_manager_receivers
(
self
):
"""
The mail should be sent to the email addresses specified in
settings.MANAGERS.
"""
call_command
(
'sendtestemail'
,
'--managers'
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
mail_message
=
mail
.
outbox
[
0
]
self
.
assertEqual
(
sorted
(
mail_message
.
recipients
()),
[
'admin_and_manager@example.com'
,
'manager@example.com'
,
])
def
test_admin_receivers
(
self
):
"""
The mail should be sent to the email addresses specified in
settings.ADMIN.
"""
call_command
(
'sendtestemail'
,
'--admins'
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
mail_message
=
mail
.
outbox
[
0
]
self
.
assertEqual
(
sorted
(
mail_message
.
recipients
()),
[
'admin@example.com'
,
'admin_and_manager@example.com'
,
])
def
test_manager_and_admin_receivers
(
self
):
"""
The mail should be sent to the email addresses specified in both
settings.MANAGERS and settings.ADMINS.
"""
call_command
(
'sendtestemail'
,
'--managers'
,
'--admins'
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
manager_mail
=
mail
.
outbox
[
0
]
self
.
assertEqual
(
sorted
(
manager_mail
.
recipients
()),
[
'admin_and_manager@example.com'
,
'manager@example.com'
,
])
admin_mail
=
mail
.
outbox
[
1
]
self
.
assertEqual
(
sorted
(
admin_mail
.
recipients
()),
[
'admin@example.com'
,
'admin_and_manager@example.com'
,
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment