Set the value of :domain to the domain you’re using for Google Apps, and :user_name and :password to your Google Apps account credentials. In the second block replace :host with the domain where the application is reachable from. The :host option is used to ensure that all links in email templates generate full URLs.

The Message Model

To allow validation of the message, I create a model and just include ActiveModel’s validations. Allowing the model to be written just like any other Rails model.

Create the file app/models/message.rb, or with a name of your choice. Make the file look similar to the following.

This is fairly self explanatory. A message can have a subject and body, as well as the name and email address of the sender. All of the fields are required, and the email address is verified with a regular expression.

Replace :to, :from and :subject with the address you’d like the email sent to, the address it’s being sent from (should be the one you configured the Rails application with), and the subject of the email.

Create the file:

app/views/notifications_mailer/new_message.text.erb

How the message looks is entirely up to you. Here’s an example of how it could be laid out.