Gmail API(via IMAP) In Ruby on Rails – A piece of cake

Adding Gmail IMAP directly into a Rails application is quite easy. As Pramod explains in this post.

Curious Reflections

We often need to read user email messages from Gmail, In this post I will be taking you through how to access user inbox messages from Gmail using gmail_xoauth gem and Ruby Net::IMAP Net library in your Rails application.

I have the sample example file on gist , I would suggest refer this example side by side with this post.

gmail_xoauth allows you to authenticate Gmail IMAP and STMP via OAuth, using the standard Ruby Net libraries. Gmail Platform provides XOAUTH2 mechanism a OAuth 2.0 protocol used for IMAP AUTHENTICATE and SMTP AUTH commands.

Ruby implements Internet Message Access Protocol (IMAP) client functionality in Net::IMAP Net libraries.

Before we start here are some prerequisite,

1) You need to Authorize user via Google using omniauth-google-oauth2 with omniauth configuration specified in sample omniauth_config.rb

2) While Authorize you must define following scopes.

3) If you are accessing user email in offline mode then you need…

View original post 260 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.