Send Emails in Ruby

If you ever need to send emails from ruby, use the mail gem. Run

gem install mail

to install the gem. Here’s how to send an UTF-8 encoded multipart mail via SMTP and TLS.

require 'mail'

m = do
  delivery_method :smtp, {
    :address => '',
    :domain => '',
    :user_name => 'smtp_login',
    :password => 'smtp_password',
    :enable_starttls_auto => true,
    :authentication => :plain,

  from    ''
  to      ''
  subject 'Testing, 1, 2, 3!'

  text_part do
    content_type 'text/plain; charset=UTF-8'
    body 'Hi there!'

  html_part do
    content_type 'text/html; charset=UTF-8'
    body '<html><body><h1>Hi there!</h1></body></html>'

This entry was posted in Ruby and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>