Android Question imap ?

wl

Well-Known Member
Licensed User
Longtime User
Erel,

I don't get it: SMTP is for sending email, IMAP (mostly) for receiving emails ?
POP3 becomes less and less popular, so ...

Tx
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
You can make your own library. IMAP is not that complicated. Read up on the relevant documents and it's pretty straightforward.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Yes that is indeed possible, but I guess that the SSL part of it can not be implemented easily.

I would go for wrapping the JavaMail Android port instead.
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
I think there is some library for SSL, but my memory has on occasion been wrong (although I can't remember such an occasion).
 
Upvote 0

3fazeac

Member
Licensed User
Longtime User
I wonder if the b4a community could encourage a competent library builder to build an IMAP library to control email on remote servers. There appears to be quite a lot of demand. Along with others, it seems, I've been waiting a couple of years for an IMAP library. I'd be quite happy to contribute financially for such a library: maybe other developers are of a like mind?
 
Upvote 0

b4auser1

Well-Known Member
Licensed User
Longtime User
Please find the project in the attached file. The project presents how to use JavaObject to access IMAPSClient from Apache Commons Net library.
Also you have to download commons-net-3.3-bin.zip from http://commons.apache.org/proper/commons-net/download_net.cgi, extract commons-net-3.3\commons-net-3.3.jar and copy commons-net-3.3.jar to the Additional libraries folder.

P.S. I can make a module wrapping all the methods of IMAPSClient with JavaObject. It will require more time. Please let me know if you would like to wait for it or will create the module by yourself.
 

Attachments

  • IMAPMail.zip
    6.3 KB · Views: 178
Upvote 0

3fazeac

Member
Licensed User
Longtime User
Please find the project in the attached file. The project presents how to use JavaObject to access IMAPSClient from Apache Commons Net library.
Also you have to download commons-net-3.3-bin.zip from http://commons.apache.org/proper/commons-net/download_net.cgi, extract commons-net-3.3\commons-net-3.3.jar and copy commons-net-3.3.jar to the Additional libraries folder.

P.S. I can make a module wrapping all the methods of IMAPSClient with JavaObject. It will require more time. Please let me know if you would like to wait for it or will create the module by yourself.

Thank you for your response. I got quite a lot further. I got over the StrictMode$AndroidBlockGuardPolicy restriction using agraham's threading library which was required to call methods which create sockets (cant be done on the main thread). However, I cant find good documentation on how to use the RunMethod syntax. Example: how do you invoke the "connect" function which has arguments connect(InetAddress host, int port) ? Do you know? It's easy when there are no arguments, of course.

Once I've got the basic connection and 'send command' figured I'll be able to proceed on my own.

Thanks for your help.
 
Upvote 0

b4auser1

Well-Known Member
Licensed User
Longtime User
B4X:
Public Sub Apache_Commons_Net_IMAPSClient_connect(a_joIMAPSClient As JavaObject, hostname As String, port As Int)
    a_joIMAPSClient.RunMethod("connect", Array As Object(hostname, port))
End Sub
 
Upvote 0

3fazeac

Member
Licensed User
Longtime User
B4X:
Public Sub Apache_Commons_Net_IMAPSClient_connect(a_joIMAPSClient As JavaObject, hostname As String, port As Int)
    a_joIMAPSClient.RunMethod("connect", Array As Object(hostname, port))
End Sub

Thanks for your help. I have a basic IMAP connection to a gmail account now. I am able to count, read and delete email messages in any selected mail box.
 
Upvote 0

3fazeac

Member
Licensed User
Longtime User
Well done you guys!!

@3fazeac: Any chance you will share your code?

I will upload what I've written. Remember that it's just a couple of days work. Hopefully people can take this as a starting point and create a fully functional imap library.

The example program has several hard-coded string constants and limited error handling but it is short and simple and functional.

Apart from the b4a program, here are the other things you have to do to get things working:
1) get commons-net-3.3.jar off the internet (probably as a .zip file) and put the commons-net-3.3.jar in Programs-Files/AnywhereSoftware/Basic4Android/Libraries
2) get agraham's Threading 1.10 library, insert into the /Libraries folder too
3) in the b4a project, in the Libs tab, select JavaObject and Threading (and Core, of course)

4) in Project->Build Configurations, in the Conditional Symbols field, add Apache_Commons_Net
It's the same string as on line 9 of the b4a program

5) in the Project->Manifest Editor, insert permission.INTERNET and permission.ACCESS_NETWORK_STATE
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<supports-screens android:largeScreens="true"
etc

6) get your gmail account open in a browser and create a gmail folder called imaptest
7) copy some unimportant small emails into the imaptest gmail folder

8) edit the imap.b4a code and on about line 44 enter your gmail username and password

9) make sure that Layout1.bal is in the Files subdirectory

10) The output from the program is all to the log console so have access to that somehow. (I ran everything with the phone connected to the PC) I don't know how it would work with the simulator.

Good luck and share any tips.
 

Attachments

  • imap.zip
    8.3 KB · Views: 183
Upvote 0
Top