| You are here: | About>Computing & Technology>Email> How Email Works> Email Programming Tips> How to Send Email with Ruby on Rails - About Email |
![]() |
This tip is known to work withHow to Send Email with Ruby on RailsEmail messages are a perfect match for Ruby's strict object orientation — each email an instance of a general Email class —, and the message contents fit Rail's template approach perfectly — many of the emails you send from your web-based app will be very similar. A match made in programmer heaven, sending mail from Ruby on Rails can still be a bit more tricky than anticipated. But by no means is it hard, and the flexibility is awesome.
Send Email with Ruby on RailsTo send an email message from a Ruby on Rails app: First, create a mailer for use in your application.
ConfigurationConfigure the mailer for your system.
Adjust the settings for your needs. If your SMTP server does not require authentication, remove the :user_name, :password and :authentication lines altogether. For more options, see the ActionMailer::Base class documentation. A Method for a MessageIt's high time to create the method in the MyMailer class that sets the stage for messages being sent.
The Message TemplateThe message body will be taken from an ActionView template, in which the body parameters from above are available.
Creating and Sending a MessageFinally, call the (automatically generated) deliver_mail() class method from the desired controller:
To send an email from vanilla Ruby, you can use the Net::SMTP class. This tip is known to work with |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


