Some fixes for mailer module.
This commit is contained in:
parent
6f7682d6a0
commit
c936813967
6 changed files with 41 additions and 40 deletions
|
@ -15,7 +15,8 @@ class MessagesController < ApplicationController
|
|||
@message = @current_user.send_messages.new(params[:message])
|
||||
if @message.save
|
||||
#FIXME: Send Mails wit ID instead of using message.state ...
|
||||
call_rake :send_emails
|
||||
#call_rake :send_emails
|
||||
@message.deliver
|
||||
redirect_to messages_url, :notice => "Nachricht ist gespeichert und wird versendet."
|
||||
else
|
||||
render :action => 'new'
|
||||
|
|
|
@ -2,24 +2,19 @@
|
|||
# ActionMailer class that handles all emails for the FoodSoft.
|
||||
class Mailer < ActionMailer::Base
|
||||
|
||||
layout 'email' # Use views/layouts/email.html.erb
|
||||
layout 'email' # Use views/layouts/email.txt.erb
|
||||
|
||||
default :from => "FoodSoft <#{Foodsoft.config[:email_sender]}>"
|
||||
default from: "FoodSoft <#{Foodsoft.config[:email_sender]}>"
|
||||
|
||||
# Sends an email copy of the given internal foodsoft message.
|
||||
def foodsoft_message(message, recipient)
|
||||
@body = message.body
|
||||
@sender = message.sender.nick
|
||||
@recipients = recipient.nick
|
||||
@reply = url_for(:controller => "messages", :action => "reply", :id => message.id)
|
||||
@link = url_for(:controller => "messages", :action => "show", :id => message.id)
|
||||
@profile = url_for(:controller => "home", :action => "profile")
|
||||
@message = message
|
||||
|
||||
mail :sender => Foodsoft.config[:email_sender],
|
||||
:errors_to => Foodsoft.config[:email_sender],
|
||||
:subject => "[#{Foodsoft.config[:name]}] " + message.subject,
|
||||
:to => recipient.email,
|
||||
:from => "#{message.sender.nick} <#{message.sender.email}>"
|
||||
mail sender: Foodsoft.config[:email_sender],
|
||||
errors_to: Foodsoft.config[:email_sender],
|
||||
subject: "[#{Foodsoft.config[:name]}] " + message.subject,
|
||||
to: recipient.email,
|
||||
from: "#{message.sender.nick} <#{message.sender.email}>"
|
||||
end
|
||||
|
||||
# Sends an email with instructions on how to reset the password.
|
||||
|
|
|
@ -43,15 +43,15 @@ class Message < ActiveRecord::Base
|
|||
|
||||
def reply_to=(message_id)
|
||||
message = Message.find(message_id)
|
||||
add_recipients(message.sender.to_a)
|
||||
add_recipients([message.sender])
|
||||
self.subject = "Re: #{message.subject}"
|
||||
self.body = "#{message.sender.nick} schrieb am #{I18n.l(message.created_at.to_date)} um #{I18n.l(message.created_at, :format => :time)}:\n"
|
||||
self.body = "#{message.sender.nick} schrieb am #{I18n.l(message.created_at, :format => :short)}:\n"
|
||||
message.body.each_line{ |l| self.body += "> #{l}" }
|
||||
end
|
||||
|
||||
def mail_to=(user_id)
|
||||
user = User.find(user_id)
|
||||
add_recipients(user.to_a)
|
||||
add_recipients([user])
|
||||
end
|
||||
|
||||
# Returns true if this message is a system message, i.e. was sent automatically by the FoodSoft itself.
|
||||
|
@ -67,20 +67,24 @@ class Message < ActiveRecord::Base
|
|||
User.find(recipients_ids)
|
||||
end
|
||||
|
||||
def deliver
|
||||
for recipient in recipients
|
||||
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
|
||||
begin
|
||||
Mailer.foodsoft_message(self, recipient).deliver
|
||||
# rescue
|
||||
# logger.warn "Deliver failed for #{recipient.nick}: #{recipient.email}"
|
||||
end
|
||||
end
|
||||
end
|
||||
update_attribute(:email_state, 1)
|
||||
end
|
||||
|
||||
# Sends all pending messages that are to be send as emails.
|
||||
def self.send_emails
|
||||
messages = Message.pending
|
||||
for message in messages
|
||||
for recipient in message.recipients
|
||||
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
|
||||
begin
|
||||
Mailer.foodsoft_message(message, recipient).deliver
|
||||
rescue
|
||||
logger.warn "Deliver failed for #{recipient.nick}: #{recipient.email}"
|
||||
end
|
||||
end
|
||||
end
|
||||
message.update_attribute(:email_state, 1)
|
||||
message.deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<%= yield %>
|
||||
|
||||
--
|
||||
FoodSoft: <%= url_for(:controller => "home", :action => "index", :only_path => false) %>
|
||||
FoodSoft: <%= root_url %>
|
||||
Foodcoop-Homepage: <%= Foodsoft.config[:homepage] %>
|
||||
Hilfe/Help: <%= Foodsoft.config[:help_url] %>
|
13
app/views/mailer/foodsoft_message.text.erb
Normal file
13
app/views/mailer/foodsoft_message.text.erb
Normal file
|
@ -0,0 +1,13 @@
|
|||
Foodsoft-Nachricht
|
||||
|
||||
Von: <%= @message.sender.nick %>
|
||||
|
||||
======================================================================
|
||||
|
||||
<%= @message.body %>
|
||||
|
||||
======================================================================
|
||||
|
||||
Antworten: <%= new_message_url('message[reply_to]' => @message.id) %>
|
||||
Nachricht online einsehen: <%= message_url(@message) %>
|
||||
Nachrichten-Einstellungen: <%= my_profile_url %>
|
|
@ -1,12 +0,0 @@
|
|||
Foodsoft-Nachricht
|
||||
|
||||
Von: <%= @sender %>
|
||||
An: <%= @recipients %>
|
||||
|
||||
======================================================================
|
||||
<%= @body %>
|
||||
======================================================================
|
||||
|
||||
Antworten: <%= @reply %>
|
||||
Nachricht online einsehen: <%= @link %>
|
||||
Nachrichten-Einstellungen: <%= @profile %>
|
Loading…
Reference in a new issue