1. Products
  2.   Email
  3.   Ruby
  4.   Pony
 
  

Open Source Ruby API to Generate & Send Emails 

Free Ruby Library that enables developers to send an email message with a single command, add attachments & custom headers to email messages,  and so on.

What is Pony Library?

Pony is a very useful library that gives software programmers the ability to manage their email messages right from their own applications using Ruby commands. The library is very powerful and like PHP's mail() function sends an email message with just a single Ruby command. It also supports the use of SMTP to localhost. The library is open source and is freely available under the MIT License for public use.

The library is very stable and can be easily integrated with other applications. There are several important features part of the library that makes developer's job easy such as sending email messages, adding attachments to email messages, using custom mail headers, handling mails with both text and HTML bodies, sending an email message via cc and BCC options, encryption and decryption support and many more.

Previous Next

Getting Started with Pony

The easiest way to install the Pony library is via RubyGems. Please use the following command for easy installation.

Install Pony via Rubygems

 gem install pony

Send Email Message via Ruby API

The open source Ruby library Pony gives software engineers the ability to compose and send email messages with just a single ruby command from their own applications. It is also possible to send email messages using SMTP sever. The library also included support to send messages to multiple users with ease. You can easily attach images as well as documents to your email messages. One other great feature is that it supports both text and HTML bodies. The following example guide software developers to create and send an email messages using sendmail command and SMTP inside their Ruby apps.

How to Send an Email Message inside Ruby Applications?

Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail

# You also Specify options for SMTP
Pony.mail({
  :to => 'you@example.com',
  :via => :smtp,
  :via_options => {
    :address        => 'smtp.yourserver.com',
    :port           => '25',
    :user_name      => 'user',
    :password       => 'password',
    :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain         => "localhost.localdomain" # the HELO domain provided by the client to the server
  }
})

Send Emails with Attachments via Ruby

Sometimes an organization needs to share all the necessary documents with their team members quickly and at a lesser expense. The Pony library makes their job easy by enabling them to send emails with attachments using a couple of lines of Ruby code. The library also supports accessing and viewing the attached files. You can easily attach single or multiple files using the attachments option. It is very simple to attach files to an email messages by using the attachments option. The following example shows how to achieve it inside Ruby applications.

How to Send an Email Message inside Ruby Applications?

Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail

# You also Specify options for SMTP
Pony.mail({
  :to => 'you@example.com',
  :via => :smtp,
  :via_options => {
    :address        => 'smtp.yourserver.com',
    :port           => '25',
    :user_name      => 'user',
    :password       => 'password',
    :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain         => "localhost.localdomain" # the HELO domain provided by the client to the server
  }
})

How to Send Emails with Attachments using Ruby API?

Pony.mail(..., :attachments => {"foo.zip" => File.read("path/to/foo.zip"), "hello.txt" => "hello!"}

Custom Mail Headers Support

Email headers are a very useful part of email messages that are used to see information about the email sender, location, and receiver, message server, and so on. The open source Pony library has provided support for specifying custom mail headers using Ruby code. You can add options for each part of the letter in the text as well as in HTML. Here is a useful example that shows, how software developers can specify custom email headers inside their own ruby applications.

How to Specify Custom Headers for Email Messages and Send It using Ruby Code?

Pony.mail(
  :to => 'me@example.com',
  :headers => { "List-ID" => "...", "X-My-Custom-Header" => "what a cool custom header" }
)
# With some additional option 
Pony.mail(
  :body => 'test',
  :html_body => 'What do you know, Joe?',
  :attachments => {"foo.txt" => "content of foo.txt"},
  :body_part_header => { content_disposition: "inline" }
)
 English