Simplest way to send mail with Ruby on Rails - ruby-on-rails

What is the simplest way to send mail using Ruby on Rails? Is there a way to send mail directly via ruby and skip all the rails models and complexity, just like php's mail() function?
Thanks for your help.

The simplest way in plain old ruby is to use net/smtp. However rails has it's own built in mailing facilities, because sending mail is something that is pretty common. The best way to do it in rails, is to use a Mailer model

Make sure you replace all the example.com's with real values:
require 'net/smtp'
Net::SMTP.start('smtp.example.com', 25) do |smtp|
smtp.send_message "Subject: testing from ruby", 'from-address#example.com', ['to-address1#example.com', 'to-address2#example.com']
end

There's also TMail.

Another excellent solution is a gem called pony. It is exactly like php's mail() function. Simply and easy.

yes check out the ruby docs...http://ruby-doc.org/stdlib/
the package you want to look at is net/smtp
there is also
http://www.rfc20.org/rubymail/(ruby mail)
which is popular and make it a little easier

I'm concerned that if you don't want to use ActionMailer that maybe you just don't get rails. ActionMailer makes sending email with good templating and the like very very easy, you really should look into it.

Related

Using Phaxio with Rails 3.1 app

I am trying to use the Phaxio API to include the ability to send faxes to customers from my Rails app, however I am having difficulty trying to implement it. I know Phaxio is new and there doesn't seem to be much on it except for what is provided by their online docs, which don't really cover too much and have no examples using rails.
From what I can gather from their docs is that I need to send a request to https://api.phaxio.com/v1/send along with some parameters. In their example they use curl to do this but how would I do this from a rails controller? Is their any helper libraries out there for this or will I have to write it from scratch? I might be swinging in the dark here but any help on this subject matter would be greatly appreciated.
Thanks
I just sent over an email to you, but I'll post some example code here as well. We're currently working on a Ruby helper for Phaxio, but here's some code that should help you get started in the mean time.
You'll need to gem install mime-types first.
http://pastebin.com/jfTLn6Bq
-Josh Nankin
Co-Founder, Phaxio

What's the benefit of using mailman gem over ActionMailer?

I'm trying to understand what the benefit is here; the only I can see is avoiding a rails bootstrap every time an email is received, but I imagine this is possible with ActionMailer as well with a bit of set up. Any help would be very useful.
Chris.
http://rubygems.org/gems/mailman
The benefit is to avoid the Rails overhead, and it provides some syntax sugar. Also to avoid having to write it yourself.
The fact is though that the underpinnings of the Mailman Micro-framework are essentially the same as ActionMailer the Mail gem. You can achieve the same results using ActionMailer or just Mail without the added dependencies. It just really depends on your use case, and how much you want to write yourself.

Need an HTTP gem for rails

I'm not pleased with Net::HTTP at all, and I'm looking for a lightweight gem that will either replace that library or at the very least hide it from me.
Does anyone have any suggestions?
My vote goes to HTTParty. It's incredibly simple to use and can be as powerful as you choose. Here's a code sample:
HTTParty.get("http://maps.googleapis.com/maps/api/distancematrix/json?origins=New+York+NY&destinations=Los+Angeles+CA&mode=car&language=en&sensor=false")
Pretty simple stuff depending on what you're using it for.
Try the RestClient gem:
https://github.com/archiloque/rest-client
There are a few out there.
Ruby toolbox has a http client list: http://ruby-toolbox.com/categories/http_clients.html
Personally I usually use HTTParty... or sometimes Mechanize, it's good for submitting forms
I would recommend checking the docs of each, to see which one suits your purpose best.
Hope this helps.
You might want to check out the rest gem, it was created and tested so we could find the best performing http gems by wrapping those gems and creating a standard interface to them. Turns out HTTParty and RestClient are very slow gems so I wouldn't recommend those, although you can always swap out the underlying gem in rest to see for yourself without having to change your code (other than initialization). rest gem by default will be much, much faster.
It's also very easy to use:
#rest = Rest::Client.new()
#rest.get(url, options...)
More info: https://github.com/iron-io/rest

Rails-like routing framework

is there any rails-like routing I can use in my non-rails app? I really like the way of defining url matching. Something like:
if matcher.match("/myapp/cart/:id/create")
puts matcher[:id]
end
Something similar. I would prefer simple solution to that. Maybe a snippet or reference to some code that can be used. Or a library. Thanks
You can do it with rack also
https://github.com/mynyml/simple_router
Sounds like Sinatra may be perfect for you:
http://www.sinatrarb.com/
If you just want sinatra like routes inside a rails app you may want to try sinatrify
astaire also seems to offer the same functionality but is not compatible with rails >= 3.2 with which i tried to use it.

How do I test ActionMailer?

I am using ActionMailer for the first time. It becomes a chore having to go into the development.log to and check if they are going, and I would like to write an automated test. What is the best/most practical solution for testing ActionMailer emails on Rails?
You can try the email-spec gem. It's really good and you can test a lot of stuff with it.

Resources