Greetings,
Here are all the pieces of sending a generic (ONE template fits all)
email from Rails. In this example, I am using an ISP that I pay for and
a free SMTP server running on Windows for testing (see
www.softstack.com).
Use the generator in RadRails to create the MyMailer class:
script/generate mailer MyMailer
This produces a "my_mailer.rb" model file in the project.
=============== add to bottom of config/envionment.rb ==============
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => "smtp.hostdepot.com",
:port => 25,
:domain => "mydomain.com",
:authentication => :login,
:user_name => "mike-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org",
:password => "mypassword"
}
======== inside the my_mailer.rb model file ================
def one_email(to_addr, from_addr, msg_subject, msg_body)
@from = from_addr
@recipients = to_addr
@subject = msg_subject
@body["email_body"] = msg_body
end
========= inside the one_email.rhtml view file ===============
<%= @email_body %>
========= the call inside the organization_controller =======
...during a post of the forgot-my-password form...
send_login_reminder(org)
============== the called method ========================
def send_login_reminder(org)
msg_body = "Your login information:\n\n"
msg_body = msg_body + "User Id: #{org.user_id}\n"
msg_body = msg_body + "Password: #{org.user_password}\n\n"
msg_body = msg_body + "Product Support"
MyMailer.deliver_one_email(org.user_email_address,
"michael-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org",
"MyProduct login reminder", msg_body)
# For testing the email without sending it,
# uncomment these lines and change "deliver" above to
"create"
# email = MyMailer.create_one_email(org.user_email_address,
"michael-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org",
# "MyProduct Login reminder", msg_body)
# render(:text => "<pre>" + email.encoded +
"</pre>")
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---