Executing scripts on command line to send out email

Added by Jacky Leung about 10 years ago

http://github.com/jk2l/redmine_issue_reminder (Still beta version, will announce a proper version when all functionality done)

I have this plugin to define query also notification function that it will send out email to each assigned developer a message defined in the reminder. Now majority function is done, but I encounter the point that i fail to send out email if it is cron (it works fine for reminders/notify/:id) so I think something is missing here that prevent the tool to send out email.

I tried to includes the following lines and hope it throw some error.

      ActionMailer::Base.raise_delivery_errors = true
      ReminderMailer.deliver_send_notification(self, user.mail, issues)
      ActionMailer::Base.raise_delivery_errors = false   

but unfortunately it does not show anything. I am stuck at the point of why is it not sending out email if execute as cron.

My execute procedure:
  • /usr/bin/env ruby script/runner vendor/plugins/redmine_issue_reminder/lib/tasks/send_email_to_all.rb

Note: There is a known bug that you need to add "User.current = User.find(<id of query creater>)" due to some part of Query class design, will debug that part later

Replies (7)

RE: Executing scripts on command line to send out email - Added by Jacky Leung about 10 years ago

After some more further debugging in last few hours I found out for some reason there was no email address set if i execute it via command line (the codes work under redmine web form)

    desc "Testing" 
    task :test => :environment do
      r = Reminder.find(:first)
      m = "jacky@fishpond.co.nz" 
      i = r.query.issues(:include => [:assigned_to])

      email = ReminderMailer.deliver_send_notification(r, m, i)
      puts "Sent email to #{email.to} as main recipents"                                                                      
      puts "Sent email to #{email.cc} as cc" 
      puts "Sent email to #{email.bcc} as bcc" 
      #puts ReminderMailer.deliver_send_notification(r, m, i)
    end

and here is the output

[root@ip-10-250-62-223:/mnt/redminevol/redmine] rake reminder:send:test
(in /mnt/redminevol/redmine)
Sent email to  as main recipents
Sent email to  as cc
Sent email to  as bcc

I really run out of idea why is this happening, and I hope anyone here can help me

RE: Executing scripts on command line to send out email - Added by Jacky Leung about 10 years ago

[root@ip-10-250-62-223:/mnt/redminevol/redmine] rake reminder:send:test                      
(in /mnt/redminevol/redmine)
Sent email to jacky@fishpond.co.nz as main recipents
Sent email to  as cc
Sent email to  as bcc

fixed the email.to part, but i am still not getting email sent to my mailbox :(

RE: Executing scripts on command line to send out email - Added by Jacky Leung about 10 years ago

I tried to send email out with rake redmine:send_reminders days=7 RAILS_ENV="production", and it does not send out any email to me at all. I can confirm that there are issues returned by the Issue.find statement within that function as I manually added puts "Sending to #{assignee.mail}" inside the loop

Modified code of Mailer's reminders method:

    issues_by_assignee.each do |assignee, issues|
      puts "Sending to #{assignee.mail}"                  
      deliver_reminder(assignee, issues, days) unless assignee.nil?
    end

Output

[root@ip-10-250-62-223:/mnt/redminevol/redmine] rake redmine:send_reminders days=7 RAILS_ENV="production" 
(in /mnt/redminevol/redmine)
Sending to jacky@fishpond.co.nz

Can someone tell me why is email sending fail?

RE: Executing scripts on command line to send out email - Added by Felix Schäfer about 10 years ago

Try to see with khalsa or edavis10 on #redmine, but ActiveMailer is a finicky beast.

RE: Executing scripts on command line to send out email - Added by Jacky Leung about 10 years ago

Felix Schäfer wrote:

Try to see with khalsa or edavis10 on #redmine, but ActiveMailer is a finicky beast.

Sorry, I don't quite understand what you mean here. Does that mean I should send email or in some method to contact them?

RE: Executing scripts on command line to send out email - Added by Felix Schäfer about 10 years ago

Oh, no, sorry for not being clearer, #redmine is the IRC channel for redmine on freenode.net (I think, there is some mention of it on the main wiki page Ithink).

RE: Executing scripts on command line to send out email - Added by Jacky Leung about 10 years ago

thanks, in this case i will get on IRC maybe tomorrow or the day after

(1-7/7)