B4A Library New Net library - Android FTP, SMTP and POP3

Status
Not open for further replies.
The Net library supports FTP, SMTP and POP3 protocols. This library replaces the FTP library. Both regular connections and SSL connections are supported.
SMTP - Allows to directly connect to SMTP mail servers and send mails, including Html messages and attachments.
POP3 - Allows to directly connect to POP3 mail servers and download messages. Currently the messages are not parsed. The raw string is returned. You can use MailParser class to parse the raw messages.

Installation instructions:
- Download the attach file.
- Copy Net.xml and Net.jar to the additional libraries folder. Make sure that there are no older copies in the internal libraries folder.

V1.81 - latest version
V1.80 - SMTP, POP and FTP can be configured to use a custom trust manager. This allows accepting invalid certificates.

V1.77 - New Sender.MailFrom field. Allows setting the mail address that is sent with the MAIL command. By default it is the same as the Username field.

V1.75 - Adds a configurable timeout parameter - FTP.TimeoutMs. Default timeout is set to 60000 (60 seconds).

V1.70 - Adds support for calling with Wait For: https://www.b4x.com/android/forum/threads/b4x-net-library-ftp-smtp-pop-with-wait-for.84821/
SMTP.AdditionalHeaders map. Allows adding headers to the messages.

V1.63 - Fixes an issue with SMTP mails with attachments. The closing boundary was previously missing.
V1.62 - Fixes an issue with SMTP in StartTLS mode.
V1.61 - Fixes an issue in SMTP related to the content encoding not being set in multipart messages.

V1.60 - New method: FTP.AppendFile. Similar to UploadFile. Appends the data to an existing file if such exists. It sends the APPE FTP command.

V1.53 - Fixes an issue with FTP.CloseNow and SSL connections.

V1.52 - Adds support for different types of authentication methods (SMTP): http://www.basic4ppc.com/android/fo...d-ftp-smtp-and-pop3.10892/page-11#post-232432

V1.51 is released. Fixes an issue with FTP over SSL explicit mode.

V1.50 is released. See this link: http://www.basic4ppc.com/android/fo...d-ftp-smtp-and-pop3.10892/page-10#post-231145

V1.37 is released. This version removes the automatic escaping of '=' characters in SMTP messages. To implement it in your code you should write:
B4X:
SMTP.Body = SMTP.Body.Replace("=", "=3D")


V1.35 is released. This version adds support for STARTTLS mode.
Unlike UseSSL mode the connection is "upgraded" to a secured connection only after the client sends the STARTTLS command.
Most of the popular smtp servers support this mode, usually on port 587.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      smtpClient.Initialize("smtp.gmail.com", 587, "xxx@gmail.com", "yyy", "SmtpClient")
      smtpClient.StartTLSMode = True
   End If
End Sub
 

Attachments

  • Net.zip
    189.1 KB · Views: 991
Last edited:

biometrics

Active Member
Licensed User
I've been asked whether i can update NetExtras so it is based on Net version 1.50 instead of Net version 1.20 which is rather an old version now.
I seem to remember Erel sent me the Net library source code Feb/March last year so that i could modify it.

So can i ask Erel if it's possible to do the same again?
Can i have a copy of the Net library version 1.50 source so i can create the modified FTP and SMTP objects?

Thanks.

Martin.

Martin,

Has NetExtas been updated to match the latest Net library?
 

warwound

Expert
Licensed User
Martin,

Has NetExtas been updated to match the latest Net library?

See here: http://www.basic4ppc.com/android/forum/threads/lib-netextras.26902/#post-231566.
I updated NetExtras to match version 1.51 of the Net library - Erel kindly sent me the Net library version 1.51 source code.
I was waiting for you to reply to my post in the NetExtras thread, since then the Net library has been updated again.

Can i ask Erel to send me the source code for the latest version of the Net library and i'll again update NetExtras?

Thanks.

Martin.
 

biometrics

Active Member
Licensed User
Hi Erel,

I'm trying our the new library for FTPS explicit mode. I assume I need to use the new property to enable it?

B4X:
libFTP.UseSSLExplicit = True

I am getting the following error though:

(CertPathValidatorException) java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Do I need to set libFTP.SetCustomSSLTrustManager to something?

It's the same sample I sent you on 14 March but the login is different. Can I email it to you to try?

I can confirm it works with other software like FileZilla client on Windows for example.
 
Last edited:

biometrics

Active Member
Licensed User
Hi Erel,

Got an interesting problem that I managed to do a workaround for ...

On the Samsung Galaxy Tab 3 when downloading large files (> 150 MB) with FTP the DownloadCompleted event does not fire when the file has been downloaded. It does fire correctly on small files (< 1 MB) and on other devices. DownloadProgress does fire though.

I worked around this by monitoring the DownloadProgress event. When the local and remote files are the same size I set a 10 second timer. If DownloadCompleted fires I disable the timer. If DownloadCompleted doesn't fire then my timer fires. At that point I restart the whole FTP process (it resumes).

The only gotcha was that I had to Dim the FTP library again before the Initialize (or else it wouldn't connect again). I have it declared in Process_Globals. I saw you mention in another thread that you had to Dim it again (which is counter to what I would have expected coming from VB6).

I'm using the Net and NetExtras 1.52 libraries with SSL explicit.
 

biometrics

Active Member
Licensed User
Hi Erel,

When I run it in debug mode then the DownloadProgress event does not fire often and it appears to hang at the end. So I have to run it in release mode. I clicked Connect in the Log window and this is the result (no errors and no DownloadCompleted event):

B4X:
LogCat connected to: B4A-Bridge: samsung GT-P5200-357359055991177
--------- beginning of /dev/log/main
Failure getting entry for 0x01080a03 (t=7 e=2563) in package 0 (error -75)
Parent view is not a TextView
Failure getting entry for 0x01080a03 (t=7 e=2563) in package 0 (error -75)
Failure getting entry for 0x01080a03 (t=7 e=2563) in package 0 (error -75)
loaded /vendor/lib/egl/libEGL_POWERVR_SGX544_115.so
loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX544_115.so
loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX544_115.so
Enabling debug mode 0
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Setting install_non_market_apps has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
** Service (service1) Create **
Rejecting registerization due to mul-int/lit8 v4, v2, (#31)
Rejecting registerization due to mul-int/lit8 v4, v2, (#31)
** Service (service1) Start **
Total arena pages for JIT: 11
Total arena pages for JIT: 12
Total arena pages for JIT: 13
Total arena pages for JIT: 14
Total arena pages for JIT: 15
Total arena pages for JIT: 16
Total arena pages for JIT: 17
Total arena pages for JIT: 18
Total arena pages for JIT: 19
Total arena pages for JIT: 20
Connected to B4A-Bridge (Wifi)
Rejecting registerization due to and-int/lit16 v0, v5, (#128)
Rejecting registerization due to and-int/lit16 v0, v5, (#128)
Installing file.
Rejecting registerization due to move v5, v4, (#0)
GC_CONCURRENT freed 2610K, 41% free 6189K/10380K, paused 2ms+1ms, total 54ms
Rejecting registerization due to move v5, v4, (#0)
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:isenzo.clientele.ifa
** Activity (main) Resume **
Setting install_non_market_apps has moved from android.provider.Settings.Secure to android.provider.Settings.Global.

The Samsung Galaxy Tab 3.0 10.1 has a Intel Atom Z2560, not ARM. Don't know if that would make a difference.
 

biometrics

Active Member
Licensed User
No I have the following active:

B4X:
libPhoneWakeState.KeepAlive(True)
libPhoneWakeState.PartialLock
 

Erel

Administrator
Staff member
Licensed User
I did a test with this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim ps As PhoneWakeState
   ps.KeepAlive(True)
   FTP.Initialize("ftp", "xxx", 21, "aaa", "bbb")
   FTP.DownloadFile("/xxx", False, File.DirRootExternal, "1.dat")
End Sub

Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
   Log(NumberFormat2(TotalDownloaded, 0, 0, 0, True))
End Sub

Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
   Log(ServerPath & " " & Success)
End Sub
It successfully downloaded a 163MB file. DownloadCompleted fired at the end. I ran it in rapid debug mode.
 

biometrics

Active Member
Licensed User
As mentioned it works on other devices and also with smaller files on this device. It's specific to the Samsung Galaxy Tab 3 10.1. I have no idea why it doesn't fire but at least my workaround works. I'd obviously prefer if it worked the way it should but in the mean time we can ship the product.
 

biometrics

Active Member
Licensed User
It is not possible to set a proxy server with this library.

Hi Erel,

Is that because of the underlying libraries limitations or is it possible to add it? If it is possible to add it we can contract Martin/warwound to add it to his Net Extras as he did for us with the Download Resume (if he is available). We'll happily pay him for that work.
 
Status
Not open for further replies.
Top