# Getting Net::IMAP to work with PLAIN auth type

**URL:** <https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589>\
**Category:** Rails\
**Created:** [May 15, 2006, 10:55pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589 "2006-05-15T22:55:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 15, 2006, 10:55pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/1 "2006-05-15T22:55:22Z")

</div>

Hi there,

```
        I'm new to rails and I've been successful tinkering around 

```

but  
am miffed by the process of trying to connect to my mail server to  
receive  
email for ActiveMailer parsing. I’m hosted on TextDrive and have read  
the  
following article on the RubyonRails wiki:  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowToReceiveEmailsWithActionMailer).

I want to connect to my TextDrive hosted email account using Net::IMAP  
but  
the problem is that the authentication method is ‘PLAIN.’ I’ve been  
searching to find a good example of how to connect to an IMAP mailbox  
using  
the PlainAuthenticator, but I haven’t come up with anything. Can anyone  
provide a code example of how to connect to an IMAP mailbox using the  
‘PLAIN’ authentication method?

Thanks,

-Alex

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 16, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/2 "2006-05-16T17:26:27Z")

</div>

Use the ‘login’ method instead of ‘authenticate’.

On May 16, 2006, at 5:53 AM, Alex Ressi wrote:

> Thanks,
> 
> -Alex
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Dae San H.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 16, 2006, 8:19pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/3 "2006-05-16T20:19:59Z")

</div>

On May 16, 2006, at 8:23 AM, Dae San H. wrote:

> Use the ‘login’ method instead of ‘authenticate’.  
> This won’t work if the IMAP server doesn’t support LOGIN. Mine doesn’t.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 16, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/4 "2006-05-16T22:10:51Z")

</div>

Eric,

So LOGIN and PLAIN authentication are two different things? Why  
doesn’t PLAIN authentication work then? I thought it was some sort  
of bug.

Which one regular GUI email clients use?

cheers,  
daesan

PS: By the way, TxD does support LOGIN.

On May 17, 2006, at 3:16 AM, Eric H. wrote:

> > 
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Dae San H.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 16, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/5 "2006-05-16T20:26:27Z")

</div>

On May 15, 2006, at 1:53 PM, Alex Ressi wrote:

> I want to connect to my TextDrive hosted email account using  
> Net::IMAP but the problem is that the authentication method is  
> ?PLAIN.? I?ve been searching to find a good example of how to  
> connect to an IMAP mailbox using the PlainAuthenticator, but I  
> haven?t come up with anything.  
> That’s because there isn’t one.  
> Can anyone provide a code example of how to connect to an IMAP  
> mailbox using the ?PLAIN? authentication method?

I wrote an implementation for IMAPCleanse, but haven’t yet submitted  
a patch to ruby-core because it should only work on SSL sockets.

Here it is:

## 

# RFC 2595 PLAIN Authenticator for Net::IMAP. Only for use with SSL

(but not

# enforced).

class Net::IMAP::PlainAuthenticator

## 

# From RFC 2595 Section 6. PLAIN SASL Authentication

# 

# The mechanism consists of a single message from the client to the

# server. The client sends the authorization identity (identity to

# login as), followed by a US-ASCII NUL character, followed by the

# authentication identity (identity whose password will be used),

# followed by a US-ASCII NUL character, followed by the clear-text

# password. The client may leave the authorization identity

empty to

# indicate that it is the same as the authentication identity.

def process(data)  
return [@user, @user, @password].join(“\0”)  
end

private

## 

# Creates a new PlainAuthenticator that will authenticate with

+user+ and

# +password+.

def initialize(user, password)  
@user = user  
@password = password  
end

end

if defined? OpenSSL then  
Net::IMAP.add\_authenticator ‘PLAIN’, Net::IMAP::PlainAuthenticator  
end

PS: This is really a question for ruby-talk.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 17, 2006, 12:41am UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/6 "2006-05-17T00:41:18Z")

</div>

On May 16, 2006, at 1:09 PM, Dae San H. wrote:

> So LOGIN and PLAIN authentication are two different things?

LOGIN sends the user and password as separately.

PLAIN sends the user and password in one ASCII NUL separated line  
(and allows you to say things like “use this users password and get  
that user’s email”)

> Why doesn’t PLAIN authentication work then? I thought it was some  
> sort of bug.

Net::IMAP doesn’t have an authenticator for PLAIN. Writing one  
wasn’t hard.

> Which one regular GUI email clients use?

Mail.app supports password (probably LOGIN and PLAIN), CRAM-MD5,  
Kerberos 4/5 and NTLM. I use SSL + PLAIN.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Alex\_Ressi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e480ec/32.png) [@Alex\_Ressi](https://www.ruby-forum.com/u/Alex_Ressi)\
**Post date:** [May 17, 2006, 6:44am UTC](https://www.ruby-forum.com/t/getting-net-imap-to-work-with-plain-auth-type/60589/7 "2006-05-17T06:44:34Z")

</div>

I’ve been using SSL + LOGIN since PLAIN didn’t seem to work. I  
didn’t realize that the authenticator was not implemented. Thanks  
Eric! I wouldn’t have figured that out by myself!

best,  
daesan

On May 17, 2006, at 7:40 AM, Eric H. wrote:

> > Why doesn’t PLAIN authentication work then? I thought it was some  
> > –  
> > Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
> > This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Dae San H.  
removed\_email\_address@domain.invalid
