EmailSender Library

EmailSender is an easy to use library to send email based on Net::SMTP. It supports the well-known encryption and authentication methods, and you can use it very easily with Gmail account.

require 'email_sender'

mailer = "", from: "")
mailer.send(to: "", subject: "Test mail", content: "This is a test mail.")


You can specify the connection parameters to SMTP server at initialization:

# simple connection
mailer = "", from: "Sender Name <>")

# encripted and authenticated connection
mailer = "", from: "Sender Name <>",
                         enctype: :ssl_tls, authtype: :plain, username: "", password: "secret")

Easier way to using Gmail account:

# minimal configuration
mailer = EmailSender.new_gmail(username: "", password: "secret")
mailer = EmailSender.new_gmail(from: "", password: "secret")

# with full sender name
mailer = EmailSender.new_gmail(from: "Sender Name <>", password: "secret")

# with another sender email address and another domain (not account
mailer = EmailSender.new_gmail(from: "Sender Name <>",
                               username: "", password: "secret")

You can modify easily the parameters of mailer object:

mailer = "", from: "")

# modify parameters
mailer.renew(server: "", from: "Sender Name <>")

# modify parameters to a Gmail account
mailer.renew_gmail(from: "Sender Name <>", password: "secret")

Send the mail to the :to, :cc and :bcc addresses with attachment:

mailer.send(to: "Receiver Name <>", subject: "Test mail",
            content: "This is a test mail.", attachment: "/path/to/file")

The :to, :cc and :bcc keys accept an email address array so you can send the message to many receivers. And the :attachment key accepts also file path array so you can attach more file:

mailer.send(to: ["Receiver Name 1 <>", "Receiver Name 2 <>"],
            cc: ["Receiver Name 3 <>", "Receiver Name 4 <>"],
            bcc: [, "", ""],
            subject: "Test mail", content: "This is a test mail.",
            attachment: ["/path/to/file1", "/path/to/file2", "/path/to/file3"])

If there are not specified the :to, :cc and :bcc addresses on sending use the initialized default addresses:

# create a mailer with default addresses
mailer = "", from: "Sender Name <>",
                         to: "Receiver Name 1 <>",
                         cc: ["Receiver Name 2 <>", "Receiver Name 3 <>"])

# send email to the default addresses
mailer.send(subject: "Test mail", content: "This is a test mail.")

You can specify the content type which is 'text/plain' by default:

mailer.send(to: "Receiver Name <>", subject: "The Ruby programming language",
            content: "<img src=''/>",
            conttype: "text/html")

The library has implemented threadsafe and support the character encoded messages.


gem install email_sender


ruby1.9.1 or greater


Copyright (C) 2012 Peter Bakonyi

EmailSender is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) version 3.0 as published by the Free Software Foundation.