I struggled for a while installing this so I thought I’d share the process, in case this helps anyone.
- Install Plugins, Extensions, etc.
- Setting Up the Mark-Up Pages
- Success!
- Troubleshooting
- Further Reading & Notes On What’s Out There
So Radiant is the great content management system for Ruby on Rails. One basic aspect of any web site is a contact form, a web form that mails, or just sending a form via mail. This is “Radiant extension mailer.” It requires “Action Mailer” Plugin from Ruby on Rails. So 3 big steps: install the plugin, the extension, then create the pages.
I configured a few very vanilla Radiant installations on Snow Leopard/sqlite3/radiant 8.1 (ruby 1.8.1, rails 2.3.2 ) to test out this mailer. I’m still checking out the extension, but this is how I got it to work. Success was to get an email from the site, in my inbox, with desired form contents.
BTW, this uses Gmail’s smtp/TLS service- sending mail via your gmail account using their servers.
1) First, get the Action Mailer & TLS plugin, by entering this from your Radiant root.
git clone git://github.com/collectiveidea/action_mailer_optional_tls.git vendor/plugins/action_mailer_optional_tls/
Next, modify your environment.rb file in two different places:
2.a) Put this code in the “config.after initialize do” block of your environment.rb file.
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "yourdomain",
:authentication => :plain,
:user_name => "yourusername",
:password => "yourpassword"
}
Note: the domain is the localhost upon which this application runs. Put in your gmail login and password.
2.b) On line 93 of a vanilla installation, you’ll see:
config.frameworks -= [ :action_mailer ]
This block basically disables it. So we want to enable it! By doing that remove it from the brackets. Now it should look like:
config.frameworks -= [ ]
To test, refresh server. Should refresh with no errors.
3) Next, install Radiant’s Mailer Extension. This will hook-up the form to page parts, and pages, and access the RoR mailer classes. From the Radiant home directory, run:
git clone git://github.com/radiant/radiant-mailer-extension.git vendor/extensions/mailer
You don’t have to run update or migrate (run Rake -T to verify) because the data is all in hashes and not stored in a database.
4) Refresh the server (should be no errors)
Setting Up Mark-Up Pages
Go to the Radiant admin interface create the following:
– Contact page. This will contain the form, using <:mailer ...> tags.
– Page part of contact called “mailer”. This contains the mail settings in YML.
– Page part of contact called “email”. This contains the email content, dynamically rendered.
– A new page, as a results page, for this example it’s called “thanks” This is a regular Radiant page.
I’m going to devote some space to each page, as they were where most of the errors lay.
Contact Page
I kept it simple, with minimal options.
Because this blog is in WordPress and I can’t use code snippets, this is an image. Sorry folks:
Note: the submit is not a :mailer model. For full options for the form, check the readme/github site.
Email Page Part
On the Contact page, add a page part called “email” and include your message.
And enter in the page, the contents of your email. Note, HTML is not supported. (There’s another extension for that- awesome_email, which I doubtlessly will review later!)
Mailer Page Part
This page, on the other hand, very picky. These are the configurations that go to Ruby on Rails’ Action Mailer process. Again, in Contact create a page part called “mailer” (lowercase).
This page part is in YML format, so it is very sensitive in regards to spaces and line endings.
This is a very simple, bare-bones example but it works. This will send to myself, from the person who submitted the form. Note: the redirect-to is *case sensitive*. So make sure the contact and thanks pages are lower case. You will see an error for that issue, if it occurs, in your server log.
OK, with that setup, you can restart your server (just for good luck?) and you’re good to go. Send yourself a message or two.
Success!
And the redirect:
TroubleShooting
Completed in 132ms (DB: 12) | 200 [http://localhost/contact/]
-> "220 mx.google.com ESMTP 7sm1568664yxg.68\r\n"
<- "EHLO banane.com\r\n"
-> "250-mx.google.com at your service, [69.109.235.40]\r\n"
-> "250-SIZE 35651584\r\n"
-> "250-8BITMIME\r\n"
-> "250-STARTTLS\r\n"
-> "250-ENHANCEDSTATUSCODES\r\n"
-> "250 PIPELINING\r\n"
<- "STARTTLS\r\n"
-> "220 2.0.0 Ready to start TLS\r\n"
<- "EHLO banane.com\r\n"
-> "250-mx.google.com at your service, [69.109.235.40]\r\n"
-> "250-SIZE 35651584\r\n"
-> "250-8BITMIME\r\n"
-> "250-AUTH LOGIN PLAIN\r\n"
-> "250-ENHANCEDSTATUSCODES\r\n"
-> "250 PIPELINING\r\n"
<- "AUTH PLAIN AGJhbmFuZQBraXdpa2l3aQ==\r\n"
-> "235 2.7.0 Accepted\r\n"
<- "MAIL FROM:
-> "250 2.1.0 OK 7sm1568664yxg.68\r\n"
<- "RCPT TO:
-> "250 2.1.5 OK 7sm1568664yxg.68\r\n"
<- "DATA\r\n"
-> "354 Go ahead 7sm1568664yxg.68\r\n"
writing message from String
wrote 599 bytes
-> "250 2.0.0 OK 1256628002 7sm1568664yxg.68\r\n"
<- "QUIT\r\n"
-> "221 2.0.0 closing connection 7sm1568664yxg.68\r\n"
Further Reading & Notes on What’s Out There
- The READMEs on GitHub, of course:
- This is really out of date: the Github Wiki on the Mailer:
- Most documentation you’ll see are sad question and answer cycles of people reading old documentation that just gets them frustrated. Example
- Snappy little post I wish I’d read before writing this one ha
- [Radiant] Mailer Extension Instructions, Very Confusing
- *the best* post ever is Shaolo’s quick writeup on how he did it. When I read this post a literal light bulb went off in my head: New question: Gmail and action mailer — Thanks Shaolo if you read this.