|
Post by vovchik on Jul 23, 2018 15:21:23 GMT 1
Dear Rik,
I think we're getting the same results. Something not quite right, yet...
With kind regards, vovchik
|
|
|
Post by Pjot on Jul 23, 2018 18:56:25 GMT 1
Hi guys, With gMail I get the same result as you. I did test the program - with my ISP POP3 server - but I did not test it with gMail The reason for the issue is the timeout setting which is defined too low. I have added a variable SSL_TIMEOUT which can be set from the client program. If you download the latest 'ssl.bac' and set a value like 2000 milliseconds after the INCLUDE (see below) then it works for me HTH Peter INCLUDE ssl
SSL_TIMEOUT = 2000 : ' <------------------- set higher if needed
' Connect to mailserver s1 = SSL_CONNECT("pop3.mail.com:995")
SSL_CMD$(s1, "USER account") resp$ = SSL_CMD$(s1, "PASS secret")
IF INSTR(resp$, "ERR") THEN PRINT "Login to mailserver failed!" END ENDIF
PRINT resp$
' Get amount of messages resp$ = SSL_CMD$(s1, "STAT")
amount = VAL(TOKEN$(resp$, 2))
PRINT "We have ", amount, " messages."
' Get a mail resp$ = SSL_CMD$(s1, "RETR 1") PRINT resp$
' Leaving server PRINT SSL_CMD$(s1, "QUIT")
' Close SSL connection SSL_CLOSE(s1)
|
|
|
Post by rikky on Jul 23, 2018 21:34:16 GMT 1
I've increased the timeout up to 200000, but nope It says that I have 0 messages. And it says that rather quickly. There is absolutely no need to increase the timeout even more. There is nothing that gives an indication of an error though. Rik.
|
|
|
Post by Pjot on Jul 23, 2018 21:41:33 GMT 1
And it says that rather quickly. Hi rikky, You defintely should experience a timeout of 2 seconds when using 2000. Are you sure you have downloaded and actually used the latest ssl.bac? Br Peter
|
|
|
Post by vovchik on Jul 23, 2018 21:58:14 GMT 1
Dear Peter,
I am also using the latest ssl.bac and am experiencing the same problem as Rik with gmail.
With kind regards, vovchik
|
|
|
Post by rikky on Jul 23, 2018 22:01:26 GMT 1
Yep. Attached. Attachments:ssl.tgz (781.06 KB)
|
|
|
Post by rikky on Jul 24, 2018 9:13:07 GMT 1
Aaarghh, I forgot the USER and the PASS keywords. s1 = SSL_CONNECT("pop.gmail.com:995")
PRINT "s1 handle : " & STR$(s1) PRINT
resp$ = SSL_CMD$(s1, "USER tadadada@gmail.com")
PRINT "response : " & resp$ PRINT
resp$ = SSL_CMD$(s1, "PASS toeperdedoempie")
PRINT "response : " & resp$
Now I get s1 handle : 1989365768
response : +OK Gpop ready for requests from 212.239.135.52 t5-v6mb25032316ljj +OK send PASS
response : +OK Welcome.
We have 260 messages.
I'm in. Next problem: My retrieved message nr 1, is not number 1 but the oldest, which is way over number 260 Next next problem The second time I retrieve mail nr 1, it is the mail one step less old, (I suppose) and so on. But, first celebrate the new achievement. Thanks. Rik.
|
|
|
Post by vovchik on Jul 24, 2018 9:58:01 GMT 1
Dear Rik, You solved it for me. We need USER and PASS, followed by a space and then our data. Yes, it works. Thanks to you and to Peter. With kind regards, vovchik
|
|
|
Post by Pjot on Jul 24, 2018 18:39:03 GMT 1
Next problem: My retrieved message nr 1, is not number 1 but the oldest, which is way over number 260 Next next problem The second time I retrieve mail nr 1, it is the mail one step less old, (I suppose) and so on. Great! So principally, it works - for the both of you Regarding your questions, it is about the way Google Mail has implemented their POP3 server. - Google Mail always will start at the oldest mail. But there is a workaround: you can prefix your user login name with "recent:" to make sure to start at the newest mail, as follows: PRINT SSL_CMD$(s1, "USER recent:myaccount")
But this is not to the POP3 standard of course. - Google Mail will mark the particular message as "Read" when using the RETR-method. - If you have a lot of unread mail, then the mail client can only retrieve them in batches of approx. 250-300 mails. You need to adapt the program to repeatedly obtain your complete unread mail in several batches. ----------- In the meantime, I have improved the ' ssl.bac' further. The SSL_TIMEOUT, which uses the WAIT function, needed to really wait out each step in order to make sure that all data got in. This made the communication kind of slow. The POP3 spec however clearly states that each response from the server should end with a 'crnl' pair, and a multi line response should end with '.crnl'. The ssl.bac context now allows to break off as soon as it detects that the end marker for the incoming data is retrieved, which makes communication a lot faster. This is a new demonstration program for the POP protocol. I am using LIST here, instead of RETR. A real mail client is left as an exercise to the reader Please fill in the right credentials before using, and make sure to really use the latest ssl.bac. INCLUDE ssl
' Set the timeout to 5000 msecs maximum SSL_TIMEOUT = 5000
' All requests to the POP3 server should be appended with CRNL SSL_APPEND_MARK$ = CR$ & NL$
' Incoming data is terminated with CRNL SSL_ENDING_MARK$ = CR$ & NL$
' Connect to mailserver s1 = SSL_CONNECT("pop.gmail.com:995")
' The connect already generates data from POP3 server, flush SSL buffer PRINT "CONNECT: ", SSL_CMD$(s1, "")
' Send user string PRINT "USER: ", SSL_CMD$(s1, "USER account")
' Send password and check if successful resp$ = SSL_CMD$(s1, "PASS secret") IF INSTR(resp$, "ERR") THEN PRINT "Login to mailserver failed!" END ELSE PRINT "PASS: ", resp$ ENDIF
' Get amount of messages PRINT "STAT: ", SSL_CMD$(s1, "STAT")
' Get the list of mails. List gnerated multiple lines from POP server which end with ".CRNL" SSL_ENDING_MARK$ = "." & CR$ & NL$ PRINT SSL_CMD$(s1, "LIST")
' Restore ending mark, leaving server SSL_ENDING_MARK$ = CR$ & NL$ PRINT "RSET:", SSL_CMD$(s1, "RSET") PRINT "QUIT:", SSL_CMD$(s1, "QUIT")
' Close SSL connection SSL_CLOSE(s1)
PRINT "Closed."
Lastly, it also is possible to perform a plain HTTP GET using the SSL_CMD$ function. ' All requests to the HTTP server should be appended with CRNLCRNL SSL_APPEND_MARK$ = CR$ & NL$ & CR$ & NL$
' Received HTTP data has no specific termination SSL_ENDING_MARK$ = ""
' Connect to webserver s1 = SSL_CONNECT("www.google.com:443")
' Send a request, make sure the server disconnects to avoid long timeout PRINT "GET: ", SSL_CMD$(s1, "GET / HTTP/1.1\r\nHost: " & SSL_web$(STR$(s1)) & "\r\nConnection: close")
' Close SSL connection SSL_CLOSE(s1)
PRINT "Closed."
Regards Peter
|
|
|
Post by rikky on Jul 25, 2018 17:35:28 GMT 1
Since the latest ssl.bac, I have to do 1 STAT first for nothing, (for it gives 0), and then one STAT for real, and only after that, everything else goes smoothly. otherwise everything is weird, like as if .. I don't know the words in English ... glue probably USER recent:blablabla LIST +OK 12 messages (763041 bytes) 1 228970 2 103673 3 472 4 435 5 595 6 5122 7 69297 8 34620 9 167489 10 428 11 57262 12 422
contrary to what you might expect the number 12 is the most recent mail TOP 12 0 +OK message follows MIME-Version: 1.0 Received: by 2002:a1c:8283:0:0:0:0:0 with HTTP; Wed, 25 Jul 2018 07:38:22 -0700 (PDT) Date: Wed, 25 Jul 2018 16:38:22 +0200 Delivered-To: blabla@gmail.com Message-ID: <CABUJP-ETfCMhyeTbR4PTCbk0060mSGA2rSKOGXuqH4wqXrGnqw@mail.gmail.com> Subject: test2 From: Rik <bla@gmail.com> To: rik <bla@gmail.com> Content-Type: text/plain; charset="UTF-8"
The id**ts, they think upside down. DELE 12 +OK marked for deletion QUIT So to see the newest message would be something like most_recent_mail$ = SSL_CMD$(s1, "TOP " &TOKEN$(SSL_CMD$(s1, "STAT"), 2) & " 0")
There doesn't seem to be a command for SEND however. Rik.
|
|
|
Post by rikky on Jul 26, 2018 5:37:09 GMT 1
So, what do I mean with glue? Even if you do STAT twice, or a hundredfold, the 'glue' is still there, I noticed. It's best to be explained by adding a TALK2GMAIL routine WHILE 0=0 INPUT "command : " , command$ resp$ = SSL_CMD$(s1, command$) PRINT resp$ IF command$ = "QUIT" THEN BREAK WEND You see? You fill in LIST, and you get the response of the command before. You fill in STAT, and you get your LIST You fill in TOP 1 0 and you get your STAT Always 1 behind. Like there is some glue sticking in the SSL_CMD$(glue) Rik.
|
|
|
Post by rikky on Jul 26, 2018 8:06:44 GMT 1
Well sending mail from a terminal is possible by talking (typing) directly to gmail. pi@buro:~ $ openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf
me => helo blablabla gmail_response => 250 smtp.gmail.com at your service me => auth login gmail_response => 334 VXNlcm5hbWU6 me => 1234abcd== gmail_response => 334 UGFzc3dvcmQ6 me => 5678efgh== gmail_response => 235 2.7.0 Accepted me => mail from:<me@gmail.com> gmail_response => 250 2.1.0 OK o12-v6sm383885edi.41 - gsmtp me => rcpt to:<me@gmail.com> gmail_response => 250 2.1.5 OK o12-v6sm383885edi.41 - gsmtp me => Data gmail_response => 354 Go ahead o12-v6sm383885edi.41 - gsmtp me => From:rik me => To:rik me => Subject: test 7 me => me => This is the body of the test me => . me => me => cntrl_D gmail_response => DONE
notes: 1234abcd== is in fact $(echo username | base64) 5678efgh== is in fact $(echo password | base64) The < and > in mail from: and rcpt to: are very very important The empty line after Subject: test 7 is very very important PS edit: I believe the dot and or empty line after the body is/are also important, because my second test (nr 8) without them failed. Well,.... Unfortunately.. s1 = SSL_CONNECT("smtp.gmail.com:587") hangs forever. No need to try the rest. Rik.
|
|
|
Post by vovchik on Jul 26, 2018 11:01:33 GMT 1
Dear Rik, I see you are getting somewhere and making progress. It may be helpful to look at the code of claws-mail or a command-line mailer or code-snippet to see how they handle gmail using pop and ssl. It should then be possible to make sense of gmail's handing of commands and to make a bacon command-line version. With kind regards, vovchik
|
|
|
Post by Pjot on Jul 26, 2018 17:02:44 GMT 1
Hi rik, Very interesting! Though a mail server using STARTTLS is not the same as a mail server using TLS. In case of STARTTLS, the client needs to setup a TCP connection in plain text, and during the session STARTTLS is submitted to indicate that the connection should change to TLS. If the client does not support that, the connection remains active as a plain text connection. In our case, using ssl.bac, a connection is created towards a server which immediately starts authentication using certificates and then agrees on the encryption type. In this situation, no data is being exchanged without encryption. Below an example SMTP session for the Google SMTP server using TLS by connecting at port 465. Note that I am using the new B64ENC$ function, which, coincidentally, recently has been added to BaCon 3.8 beta. Please fill in your correct credentials before running! Best regards Peter INCLUDE ssl
CONST CRNL$ = CR$ & NL$
' Set the timeout to 5000 msecs maximum SSL_TIMEOUT = 5000
' All requests to the SMTP server should be appended with CRNL SSL_APPEND_MARK$ = CRNL$
' Incoming data is terminated with CRNL SSL_ENDING_MARK$ = CRNL$
' Connect to mailserver s1 = SSL_CONNECT("smtp.gmail.com:465")
' The connect already generates data from SMTP server, flush SSL buffer PRINT "CONNECT: ", SSL_CMD$(s1, "")
' Send HELO to SMTP server PRINT "HELO: ", SSL_CMD$(s1, "HELO basic-converter.org")
' Send AUTH LOGIN to SMTP server PRINT "AUTH: ", SSL_CMD$(s1, "AUTH LOGIN")
' Account credentials PRINT "Account: ", SSL_CMD$(s1, B64ENC$("account")) PRINT "Password: ", SSL_CMD$(s1, B64ENC$("password")) PRINT "Mail from: ", SSL_CMD$(s1, "mail from:<me@gmail.com>") PRINT "Rcpt to: ", SSL_CMD$(s1, "rcpt to:<me@gmail.com>") PRINT "DATA: ", SSL_CMD$(s1, "DATA")
PRINT SSL_CMD$(s1, "From: Peter <me@gmail.com>" & CRNL$ & "To: Peter <me@gmail.com>" & CRNL$ & "Subject: test" & CRNL$ & \ CRNL$ & "Hello world" & CRNL$ & "." & CRNL$)
' Quit te connection PRINT "QUIT: ", SSL_CMD$(s1, "QUIT")
' Close SSL connection SSL_CLOSE(s1)
PRINT "Closed."
Output: BR Peter
|
|
|
Post by rikky on Jul 27, 2018 7:36:31 GMT 1
Yes It works. edit: P.S: Thanks.
|
|