Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
fe082d62
Commit
fe082d62
authored
Mar 05, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Script to e-mail users in bulk, in batches, from a text file
parent
cc13aef0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
4 deletions
+54
-4
student/management/commands/emaillist.py
+1
-4
student/management/commands/massemailtxt.py
+53
-0
No files found.
student/management/commands/emaillist.py
View file @
fe082d62
...
@@ -12,10 +12,7 @@ middleware.MakoMiddleware()
...
@@ -12,10 +12,7 @@ middleware.MakoMiddleware()
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
\
help
=
\
'''Sends an e-mail to all users. Takes a single
''' Extract an e-mail list of all active students. '''
parameter -- name of e-mail template -- located
in templates/email. Adds a .txt for the message
body, and an _subject.txt for the subject. '''
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
#text = open(args[0]).read()
#text = open(args[0]).read()
#subject = open(args[1]).read()
#subject = open(args[1]).read()
...
...
student/management/commands/massemailtxt.py
0 → 100644
View file @
fe082d62
import
os.path
import
time
from
lxml
import
etree
from
django.core.management.base
import
BaseCommand
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
import
mitxmako.middleware
as
middleware
from
django.core.mail
import
send_mass_mail
middleware
.
MakoMiddleware
()
def
chunks
(
l
,
n
):
""" Yield successive n-sized chunks from l.
"""
for
i
in
xrange
(
0
,
len
(
l
),
n
):
yield
l
[
i
:
i
+
n
]
class
Command
(
BaseCommand
):
help
=
\
'''Sends an e-mail to all users in a text file.
E.g.
manage.py userlist.txt message logfile.txt rate
userlist.txt -- list of all users
message -- prefix for template with message
logfile.txt -- where to log progress
rate -- messages per second
'''
log_file
=
None
def
hard_log
(
self
,
text
):
self
.
log_file
.
write
(
text
+
'
\n
'
)
def
handle
(
self
,
*
args
,
**
options
):
global
log_file
(
user_file
,
message_base
,
logfilename
,
ratestr
)
=
args
users
=
[
u
.
strip
()
for
u
in
open
(
user_file
)
.
readlines
()]
message
=
middleware
.
lookup
[
'main'
]
.
get_template
(
'emails/'
+
message_base
+
"_body.txt"
)
.
render
()
subject
=
middleware
.
lookup
[
'main'
]
.
get_template
(
'emails/'
+
message_base
+
"_subject.txt"
)
.
render
()
.
strip
()
rate
=
int
(
ratestr
)
self
.
log_file
=
open
(
logfilename
,
"a+"
,
buffering
=
0
)
for
users
in
chunks
(
users
,
rate
):
emails
=
[
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
u
])
for
u
in
users
]
self
.
hard_log
(
" "
.
join
(
users
))
send_mass_mail
(
emails
,
fail_silently
=
False
)
time
.
sleep
(
1
)
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