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 => “[email protected]”,
: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,
“[email protected]”,
“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,
“MyProduct Login reminder”, msg_body)
render(:text => “” + email.encoded + “
”)
end