Page 1 of 1
POP IMAP information
Posted: Tue Jul 07, 2015 9:31 pm
by cyb3rg3cko
I'm trying to communicate with gmail through the use the POP3 protocol. I've searched the web and the forums and found very little information floating around when it comes to using a secure socket with livecode. currently I'm only trying to verify communication with the "+OK ..." response from the server. I setup my address with the following code;
Code: Select all
put "gmail_pop_address" into serverAddress
put any line of hostnameToAddress(serverAddress) into socketAddress
put ":995" after socketAddress
This sets me up with an ip address and port wich i've verified is correct. Then I have tried opening a secure socket with the following methods;
Attempt 1:
Code: Select all
open socket to socketAddress with message "socketOpen"
on socketOpen
secure socket socketAddress
read from socket socketAddress until CRLF
answer "Data: " & it
end socketOpen
Attempt 2:
Code: Select all
open secure socket to socketAddress with message "socketOpen"
on socketOpen
read from socket socketAddress until CRLF
answer "Data: " & it
end socketOpen
Both attempts result in a connection being made as well as a dialog box that just contains "Data:" and no response, which you would think meant that it received at the bare minimum a CRLF ending, but even if i try to check the length of the response it comes up to 0. Please note that the code above is not a direct copy and paste from my project but an adaptation of what methods I've used. I also have a provision for a connection timeout which works when i try to connect to a non-SSL port like 110. Both POP3 or IMAP will work for my project, so information on either is welcome. I've also tried (unsuccessfully) working with Sarah Reichelt's POP library with a few modifications for SSL. I have also verified the working of the server side POP3 connection using a web based tester. I would prefer to build a small library for my particular application versus using a pre-built one, I rather enjoy learning new protocols.
Information you may want...
Livecode version - 7.0.6
Development OS - Windows/Linux(Ubuntu 15.04)
Application target OS - Both windows and Linux but primarily Linux
Thank you for any input.
Re: POP IMAP information
Posted: Tue Jul 07, 2015 9:57 pm
by SparkOut
Try adding the word "with" to attempt 2's first line.
It looks like it should work then.
Re: POP IMAP information
Posted: Wed Jul 08, 2015 11:02 am
by cyb3rg3cko
Spark out - Thanks for the reply, as I mentioned in my original post those code snippets were adaptations of what I actually had in the program and not directy cut and pasted. I checked just to verify but in the original code I did have the 'with' keyword, I will however edit my original post to reflect that.
So 40 views and no other input? I take it this isn't a common use is the world of programming livecode.
Re: POP IMAP information
Posted: Wed Jul 08, 2015 7:17 pm
by Simon
Using sockets seems more of a pain then just using the gmail api.
Simon
Edit; I take it back, gmail api requires OAuth2. Now that is a different thread.
Re: POP IMAP information
Posted: Thu Jul 09, 2015 12:57 am
by cyb3rg3cko
For anyone looking for information on this, I was able to open a secure connection to gmail's pop address using the following code;
Code: Select all
on socketConnect
put "gmail_pop_address" into serverAddress
put any line of hostnameToAddress(serverAddress) into socketAddress
put ":995" after socketAddress
open secure socket to socketAddress with message "socketOpen" without verification
end socketConnect
on socketOpen
read from socket socketAddress until CRLF
answer "Data: " & it
end socketOpen
Substitute "gmail_pop_address" for gmail's actual pop address (had to use this because the Livecode forums thought i was trying to use a web link). The important change is that I had to specify "without verification" because apparently when not declared it defaults to "with verification".
Note to LiveCode developers: The 'open secure socket' function should really be documented a bit better, I have seen many unanswered questions on the web in my attempt to find a solution and the documentation implies that the socket should already be open before attempting to secure it. However on a more positive note, I am fairly proficient in 5+ programming languages but still prefer to always try LiveCode first when building an application because of it being simple yet powerful with the ability compile for multiple platforms, Thank you for all your hard work bringing such a versatile tool to the world!
Re: POP IMAP information
Posted: Thu Jul 09, 2015 7:46 am
by SparkOut
For reasons of my own, I had been playing with Sarah's library and gmail just a few days before your question. I didn't get the library to work, but didn't spend a lot of time on it. I did get success with your "attempt 2" code.
Are you now OK with the whole thing, or are there any "next steps" within the socket communication that are still troublesome?
Re: POP IMAP information
Posted: Thu Jul 09, 2015 10:58 am
by cyb3rg3cko
Once I managed to get it to connect securely to Gmail I was able to login, retrieve mail and logout with both the imap and pop3 protocols. At this point I believe I am good to go with my application. I may however write a small email library available to anyone that will make sending and receiving with pop3, imap, and smtp protocols a breeze. On one side note I did change the attempt code to use
Code: Select all
read from socket socketAddress until 0
This enabled me to read the entire responce versus just the first line.
Re: POP IMAP information
Posted: Thu Jul 09, 2015 11:01 pm
by SparkOut
OK great, good luck and if you get to making a public library for secure email collection I would be keen to look it over.
Re: POP IMAP information
Posted: Thu Mar 24, 2016 11:22 am
by golife
I am also trying working out access to Gmail through POP3, IMAP and Gmail API (OAuth 2). Do you have such library already? Or could you post eventually the "log in" procedure script from start to end?
Re: POP IMAP information
Posted: Thu Mar 24, 2016 5:58 pm
by quailcreek
I think a lot of us would be interested in hearing more. Would your process work on iOS?