Description:
sends mass emails
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r309:5760cdcf6707 - - 3 files changed: 63 inserted, 1 deleted

@@ -0,0 +1,19
1 + %h1 Send mass e-mails
2 +
3 + - form_tag :action => 'bulk_mail' do
4 + %b List recipients' login below; one per line.
5 + %br/
6 + = text_area_tag 'login_list', nil, :rows => 7, :cols => 80
7 + %br/
8 + %b Subject:
9 + = text_field_tag 'subject', '', :size => 60
10 + %br/
11 + %b Email body:
12 + %br/
13 + = text_area_tag 'email_body', nil, :rows => 11, :cols => 80
14 + %br/
15 +
16 + = submit_tag "Send mails", :confirm => 'Are you sure?'
17 +
18 + %hr/
19 + = link_to '[go back to index]', :action => 'index'
@@ -12,7 +12,10
12 12 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
13 13 verify :method => :post, :only => [ :destroy,
14 14 :create, :create_from_list,
15 - :update ],
15 + :update,
16 + :manage_contest,
17 + :bulk_mail
18 + ],
16 19 :redirect_to => { :action => :list }
17 20
18 21 def list
@@ -301,6 +304,45
301 304 redirect_to :action => 'admin'
302 305 end
303 306
307 + # mass mailing
308 +
309 + def mass_mailing
310 + end
311 +
312 + def bulk_mail
313 + lines = params[:login_list]
314 + if !lines or lines.blank?
315 + flash[:notice] = 'You entered an empty list.'
316 + redirect_to :action => 'mass_mailing' and return
317 + end
318 +
319 + subject = params[:subject]
320 + if !subject or subject.blank?
321 + flash[:notice] = 'You entered an empty mail subject.'
322 + redirect_to :action => 'mass_mailing' and return
323 + end
324 +
325 + body = params[:email_body]
326 + if !body or body.blank?
327 + flash[:notice] = 'You entered an empty mail body.'
328 + redirect_to :action => 'mass_mailing' and return
329 + end
330 +
331 + note = []
332 + users = []
333 + lines.split("\n").each do |line|
334 + user = User.find_by_login(line.chomp)
335 + if user
336 + send_mail(user.email, subject, body)
337 + note << user.login
338 + end
339 + end
340 +
341 + flash[:notice] = 'User(s) ' + note.join(', ') +
342 + ' were successfully modified. '
343 + redirect_to :action => 'mass_mailing'
344 + end
345 +
304 346 protected
305 347
306 348 def random_password(length=5)
@@ -33,6 +33,7
33 33 <%= link_to '[View administrators]', :action => 'admin' %>
34 34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
35 35 <%= link_to '[View active users]', :action => 'active' %>
36 + <%= link_to '[Mass mailing]', :action => 'mass_mailing' %>
36 37 <% if Configuration.multicontests? %>
37 38 <br/><b>Multi-contest:</b>
38 39 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
You need to be logged in to leave comments. Login now