Digital P. wrote:
Hi,
That was sort of what I was looking for, useful for the AJAX but I need
the RoR code that connects to the ActionMailer and actually sends the
formatted email to my email address. I should have been more specific in
my first post.
Thanks Again,
Alex.
Hi Alex,
There are several steps for ActionMailer and to some degree I hope I can
help you.
First, environment.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => ‘your.smtpout.com’, # replace with your SMTP
server
:port => 80, # replace with your SMTP server’s port
:authentication => :login,
:user_name => "[email protected]",
:password => "yourpassword"
}
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = “utf-8”
Next, you need a model for mailing. Call it ContactMailer.rb or
something like that.
First line: class ContactMailer < ActionMailer::Base
This allows it to inherit from ActionMailer.
Then, in that file, create a function for your stuff: E.G.
def customer_notification(contact, sent_at = Time.now)
@subject = “Your custom subject”
@body[“contact”] = contact
@recipients = @contact.email_address
@from = “Admin or Whatever [email protected]”
@sent_on = sent_at
@headers = {}
end
Then, you need a view (contact_mailer) to format the email. I have done
this with plain text, xml and html. As per this example, create an
rhtml file called customer_notification.rhtml. The file will look
something like this:
etc...
Contact Name: <%= @contact.first_name %>
etc…
etc...
Finally, in your controller that gets the contact form submitted to, do
something like this in the action:
email = ContactMailer.create_customer_notification(@contact)
email.set_content_type(“text/html”)
ContactMailer.deliver(email)
Whew…I hope this helps. I sure hope I answered your question!
Or did I miss the request all together?
Regards,
Michael
mmodica at cox dot net