Are there any gmail imap golang WORKING sample ?

3,050 views
Skip to first unread message

alpri...@gmail.com

unread,
Aug 28, 2013, 11:41:01 AM8/28/13
to golan...@googlegroups.com
Hi everyone
It's a bit shame but i cannot find any WORKING sample to get imap access to gmail account.
google.com/p/go-imap/go1 stopped working couple months ago, github.com/NerdGGuy/go-imap cannot work as well...
 

Maxim Khitrov

unread,
Aug 28, 2013, 1:23:20 PM8/28/13
to alpri...@gmail.com, golang-nuts
On Wed, Aug 28, 2013 at 11:41 AM, <alpri...@gmail.com> wrote:
> google.com/p/go-imap/go1 stopped working couple months ago,

News to me. What about it isn't working?

Alexander Prihodko

unread,
Aug 29, 2013, 10:41:18 AM8/29/13
to Maxim Khitrov, golang-nuts
Hello Maxim

Slightly modified my code to join it to single file and remove credentials (attached). It was working before :-(
It authenticates, but unable to pull messages.

$ go run check_mailbox_imap.go 
Server says hello: Gimap ready for requests from xxx.xx.xx.xx v??????????????.42

Mailbox status:
<nil>panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x80491f0]

goroutine 1 [running]:
main.CheckMailBox(0x81b5f38, 0x5, 0x81ccf88, 0x14, 0x81c1288, ...)
        /home/al/workspace/go/src/scripts/amx/check_mailbox_imap.go:81 +0x400
main.main()
        /home/al/workspace/go/src/scripts/amx/check_mailbox_imap.go:33 +0x53

goroutine 2 [syscall]:
exit status 2


Any ideas? Than you!


Alex


2013/8/28 Maxim Khitrov <m...@mxcrypt.com>
check_mailbox_imap.go

Maxim Khitrov

unread,
Aug 29, 2013, 11:06:57 AM8/29/13
to Alexander Prihodko, golang-nuts
The line numbers in the stack trace don't match the attached file, but
I'll assume that 81 refers to "return c.Mailbox.Messages, nil". It
probably panics because c.Mailbox is nil at that point, perhaps
because the Select command failed. You need to check for errors to
figure out what the problem is. Turning on protocol logging is also
helpful.

You can run my demo script with your gmail account to verify that the
package is working:

http://code.google.com/p/go-imap/source/browse/go1/imap-demo/demo1.go
http://code.google.com/p/go-imap/source/browse/go1/imap-demo/demo1-gmail.txt

Alexander Prihodko

unread,
Sep 15, 2013, 9:12:17 AM9/15/13
to Maxim Khitrov, golang-nuts
Thank you for the answer.
Package definitely works for me. 
My problem is in gmail label's name. Somewhat i cannot reach [GMAIL]/Spam folder.
But it's not about golang and imap implementation which works perfectly.
Thank s a lot!

--
Alex


2013/8/29 Maxim Khitrov <m...@mxcrypt.com>

Maxim Khitrov

unread,
Sep 15, 2013, 10:37:59 AM9/15/13
to Alexander Prihodko, golang-nuts
Perhaps this might help:

http://developers.google.com/gmail/imap_extensions#special-use_extension_of_the_list_command

On Sun, Sep 15, 2013 at 9:12 AM, Alexander Prihodko

Hugo Schmitt

unread,
Mar 17, 2015, 9:35:56 AM3/17/15
to golan...@googlegroups.com, alpri...@gmail.com
If anyone arrives at this in 2015, for connecting in Gmail I had two surprises:

1- Must use app specific password
2- Imap address must be imap.gmail.com:993

emersion

unread,
Jun 27, 2016, 10:16:30 AM6/27/16
to golang-nuts, alpri...@gmail.com
The preferred method to login to Gmail's IMAP & SMTP server is with SASL XOAUTH2. You should use it instead of app-specific passwords.
Reply all
Reply to author
Forward
0 new messages