Tuesday, December 4, 2007

Ruby ActionMailer Reply-To

Setting Reply-To in ActionMailer is a little easier than you might think. But, you don't do it like you would expect... strangely enough, especially for Ruby.

You would expect:
to "john@john.com"
from "joe@joseph.com"
subject "Are you coming?"
body "Coming to the big event tonight?"
reply-to "inbox@joseph.com"

But NO~! You set that in the headers field:
to "john@john.com"
from "joe@joseph.com"
subject "Are you coming?"
body "Coming to the big event tonight?"
headers 'reply-to'=>'inbox@joseph.com'

Sunday, December 2, 2007

Ruby Emailer Program

Here's a Cool Ruby Emailing Program

Need to send an email through Ruby? It's really easy if you have the right packages installed.

First, define your body.

body = "Thank you for your email at #{website}. We appreciate hearing from you. If you have a matter that requires attention, we will contact you as soon as possible. For urgent issues, call #{phone}.\n\n\nThis message was sent because you filled out a contact form on #{website}. Do not reply to this message, this is an unmonitored email address.\nThanks!"

Mailer.deliver_file('delivertome@hotmail.com','Sender «sender@yoursite.com»',"Thank you for your email!", body)


But wait, now you have to define .deliver_file. This is the method that actually does the emailing:


require 'action_pack'
require 'action_mailer'

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = { :address => "localhost", :domain => 'www.yourdomain.com', :port => 25 }

class Mailer < ActionMailer::Base
def file(to, sender, subject1, body1, strip_ext = true)

#standard ActionMailer message setup
recipients to
from sender
subject subject1
#set the body without a template like this
body body1

end
end


And that's all! Make sure to define the class before you try to use it.

Get Free Ruby Scripts

Ruby is a newer language, especially compared to many of the languages that are used most often. This can make it tough for people to figure out exactly how to use Ruby. For example, there are not as many websites with good information about the language - but there is one really good ruby tutorial out there, thankfully.

Now, there is a new Ruby Scripts Library that offers a large selection of Ruby scripts to potential ruby programmers. The library currently hosts only 5 scripts, but they have a contact form for people to send in more scripts. One script, particularly useful, shows how to make thumbnails from the Ruby version of Magick.

They also plan to add several more as time goes on. A unique feature is the GoDaddy Tutorial, which teaches how to use the language with one of the world's most popular and cheapest web hosts.