Mail: An All New Ruby E-mail Library
To date, the main ways to send e-mails from Ruby have been Net::SMTP, TMail, and Rails' ActionMailer (which uses TMail). Now, however, there's a fourth option, the simply named "mail" by Mikel Lindsaar.
Mail is a new pure Ruby library designed to handle the generation, parsing, and sending of e-mail in a "Rubyesque" manner. Both the sending and receiving e-mails can be handled through the library and, where necessary, Mail proxies methods from libraries like Net::SMTP and Net::POP3. Ruby 1.9 support has been built in from day one so dealing with different text encodings in your e-mails is easier than ever (Mikel claims this is less than straightforward with TMail). Mikel also points out that Mail has 100% spec coverage.
There are lots of code examples on the Mail page but to give you an idea of how it works, here's a code example that sends an e-mail with an attachment:
Mail.defaults do smtp '127.0.0.1' # Port 25 defult end mail = Mail.new do from 'me@test.lindsaar.net' to 'you@test.lindsaar.net' subject 'Here is the image you wanted' body File.read('body.txt') add_file {:filename => 'somefile.png', :data => File.read('/somefile.png')} end mail.deliver!
As well as the main GitHub page for the Mail project, there's also a mail-ruby Google Group where questions can be asked, etc.
[ad] Find duplication, code smells, complex code and more in your Ruby code with Caliper! The metrics are free and setup takes just one click. Get started!
November 11, 2009 at 3:28 pm
Have you tried the Pony (http://github.com/adamwiggins/pony) gem? I've used it, works simply well, it's used like a php mail() call :-)
November 11, 2009 at 3:39 pm
Don't forget Pony!
http://github.com/adamwiggins/pony
November 11, 2009 at 4:51 pm
Ah yes, I totally forgot about Pony! I tried it once and it worked okay.
November 11, 2009 at 5:53 pm
Hey, as long as we're pumping other email libraries, I'll pump my ez-email library:
http://shards.rubyforge.org/wiki/wiki.pl?Ez-Email
Can't do attachments yet, I'll have to get on that. :)
November 11, 2009 at 6:49 pm
I remember that clip art!
November 11, 2009 at 7:04 pm
I did a Tineye search on it before I used it and found it's in use on hundreds of sites, so I'm guessing it's verrry popular :-)
November 12, 2009 at 12:10 am
Hey Peter,
One correction, I aim for 100% spec coverage :) Not quite there... but I am in the high 95% percentile per rcov usually.
Also, another point, in Mail I tried to bring together all the different things a mail library should do. I didn't know about Pony, and Ez-Mail, they look good.
Anyone who wants to help contribute to Mail is more than welcome. It is a full on project and needs all the bright people it can get.
Regards
Mikel
November 12, 2009 at 7:45 pm
Unfortunately, tmail doesn't attempt to parse MIME quoted_printable content. Sending mail is only half of the challenge. We desperately need a mail library with spec coverage. THANKS!
November 17, 2009 at 9:54 am
A small but equally powerful mail lib: mmmail.
http://github.com/lsegal/mmmail