" Start your business on internet, we are here to help you "

We are Software Development and Technical Service providing company from kathmandu Nepal. We use latest technologies to fulfill your requirements

Send Mail Using Ruby

Ruby     Published at 4 months ago    Arjun Ghimire

Send Mail Using Ruby

In this part of the tutorial, we’re going to use ruby gem to send mail. I assume that you’re already familiar with Ruby programming language.

Step 1: 

Create a ruby file say mail.rb and add following code:


       require 'mail'

       options = {

                  :address              => "smtp.gmail.com",
                  :port                 => 587,
                  :domain               => 'localhost',
                  :user_name            => 'example@gmail.com',
                  :password             => 'yourpassword',
                  :authentication       => 'plain',
                  :enable_starttls_auto => true 

     Mail.defaults do
         delivery_method :smtp, options

    Mail.deliver do
         to 'arjunghimire0714@gmail.com'
        from 'example@gmail.com'
        subject 'testing sendmail'
       body File.read('body.txt')

you need to add your gmail id in :user_name and gmail password in :password .


Step 2: 

Create a text file say message.txt and write some message:

 Hi, I am from message.txt file send as a message.


Step 3: 

Run file mail.rb in terminal 

arjun@arjun:~$  ruby mail.rb



That’s it! In this tutorial I’ve shown you how you send mail using Ruby Programming Language. Feel free to improve the code presented above and if you have questions, comments or suggestions drop us a line in the comments.

Thank You

To Top