Test driving Mailgun - Running the Mailgun.rb Demo

If you want your Rails application to send email, you should look into Mailgun. Another alternative would be to use Gmail with stmp set up, but using Gmail comes with some restrictions that Mailgun doesn't have. For example, in Gmail, the email sender would be displayed as the address of Gmail account. In Mailgan you can configure it to be different sender.

I was trying out this git package provided by Mailgun to try out. In this demo, I am merely trying to send email

1. I cloned the git package.

> git clone https://github.com/mailgun/mailgun.rb

2. Modify the MailgunMessage::send_text in sending-message.rb to suit your purpose.

 

MailgunMessage::send_text("xxx@xxx.com",
                          "yyy@yyy.com, 'yyy' <yyy@yyy.com>",
                          "Hello text Ruby API",
                          "Hi!\nI am sending the message using Mailgun Ruby API")

 

 

3. Run this command
> ruby samples/sending-messages.rb 

And you are good!

---

If you see an error like this 

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mailgun (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from samples/sending-messages.rb:1:in `<main>'

Add this line at the very top of sending-messages.rb
$: << File.dirname( "." )

---

Application Environment
  • rails version 3.0.10
  • ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]