Radiant Mailer Extension Installation Basics

I struggled for a while installing this so I thought I’d share the process, in case this helps anyone.

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.

Install Plugins, etc.

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:

contact_form_raw

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.

add_part_email

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!)

email

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).

addpart_mailer

This page part is in YML format, so it is very sensitive in regards to spaces and line endings.

mailer

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!

form_in_action

And the redirect:

final_thanks


TroubleShooting

  • Make sure all of your Radiant pages are published.
  • Check that there are only 2 spaces before the recipients’ dash, in the mailer page part.
  • Check that your “redirect_to” is in the same case as the actual pages.
  • The form simply “reloads” with no visible progress? If it reloads quickly, it’s probably not actually emailing – as it takes time to hit and verify the Gmail server. Check your server log.
  • If it doesn’t know where to put the result, the redirect path basically, that will be a 302 in your server log.
  • If the form refreshes with the values still in the field, and no “localhost” (or your domain) in the footer, and no mail file in the log, then the configuration of your “mailer” page part is probably wrong- or it could be an issue with your environment.rb edits.
  • If your connection to Gmail works, you will see this kind of printout in your log. If you don’t see this long acknowledgment, then it’s not really sending mail. I’d recommend double-checking your username/password, or reinstalling the action_mailer plugin (just re-git it to that directory, or check the directory to see that it’s installed right). Plugins and extensions have picky naming conventions- the action mailer plugin has to be the name of the file,as well as the “mailer” extension.
    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:\r\n”
    -> “250 2.1.0 OK 7sm1568664yxg.68\r\n”
    <- "RCPT TO:\r\n”
    -> “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

    • anthonyhsiao

      Hi - I got it to work but then suddenly it stopped working again, and then at some point it worked for some email recipient address of mine but not for another. I was wondering - do you have any advice on how to debug this more effectively? There seems to be no clear way to identify where in the chain this is breaking...

    • anthonyhsiao

      Ok - I solved my problem - for reference - I was using the heroku sendgrid addon and it adds emails to bounce lists - and I was playing with the contact form with lots of garbage email addresses, so it ultimately added my valid email ad to the bounce list. after clearing it it worked again!

    • danigb

      It didn't work for me until I add :enable_starttls_auto => true into the smtp_settings hash.

    • Chaitanya Saraf1985

      Nice One!!! Thats the exactly what i need, Thanks a lot

    • If a jewel falls into the mire, it remains as precious as before; and though dust should ascend to heaven, its former worthlessness will not be altered.

    blog comments powered by Disqus