Hi, I have a set of messages stored in the db. These are email messages that I have to send based on some condition. This is not the way I had been doing all these days. I used to create an action in my controller (class Notifier < ActionMailer::ARMailer) and then create an rhtml file with the email content and then say Notifier::deliver_my_email_message to send out the emails. But now that I am storing these messages in the database, is there a way I can define the controller action and view dynamically and then pass the message as a parameter? Or is there a better way to handle this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you want to send emails which are stored in your database, you can use
something similar to the following:
class MyMailer < ActionMailer::Base
def from_database(email)
@subject = email.subject
@to = email.recipient
@from = email.from_address
@body = email.body
end
end
class MyController < ApplicationController
def send_email
email = EmailTemplate.find_by_id([:id])
mailer = MyMailer.deliver_from_database(email)
end
end
This is old code and I haven''t done this in a while, so there might be
a
better way to do it now.
Adam
On 3/17/08, Love AJAX <loveajax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Hi,
>
> I have a set of messages stored in the db. These are email messages
> that I have to send based on some condition. This is not the way I had
> been doing all these days. I used to create an action in my controller
> (class Notifier < ActionMailer::ARMailer) and then create an rhtml
> file with the email content and then say
> Notifier::deliver_my_email_message to send out the emails. But now
> that I am storing these messages in the database, is there a way I can
> define the controller action and view dynamically and then pass the
> message as a parameter?
>
> Or is there a better way to handle this?
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks much Adam. This makes sense. -subbu On 3/16/08, Adam Cohen <ocdrails-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you want to send emails which are stored in your database, you can use > something similar to the following: > > > class MyMailer < ActionMailer::Base > def from_database(email) > @subject = email.subject > @to = email.recipient > @from = email.from_address > @body = email.body > end > end > > > class MyController < ApplicationController > def send_email > email = EmailTemplate.find_by_id([:id]) > mailer = MyMailer.deliver_from_database(email) > end > end > > This is old code and I haven''t done this in a while, so there might be a > better way to do it now. > > > > Adam > > > > > On 3/17/08, Love AJAX <loveajax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > I have a set of messages stored in the db. These are email messages > > that I have to send based on some condition. This is not the way I had > > been doing all these days. I used to create an action in my controller > > (class Notifier < ActionMailer::ARMailer) and then create an rhtml > > file with the email content and then say > > Notifier::deliver_my_email_message to send out the > emails. But now > > that I am storing these messages in the database, is there a way I can > > define the controller action and view dynamically and then pass the > > message as a parameter? > > > > Or is there a better way to handle this? > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---