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.b4x.com/android/forum/th...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.b4x.com/android/forum/th...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, "[email protected]", "yyy", "SmtpClient")
      smtpClient.StartTLSMode = True
   End If
End Sub
 

Attachments

  • Net.zip
    189.1 KB · Views: 3,060
Last edited:

JATAIDE

Member
Licensed User
Longtime User
WHEN I use the net library v 1.53, there is no error in the compilation of the program, but in execution it crashes.
can you help me
Tablet Samsung 10
b4A v 2.52

thank you
 

JATAIDE

Member
Licensed User
Longtime User
Yes. But only if you post the error message from the logs.


error message

~i:** Activity (main) Resume **
~i:** Activity (main) Pause, UserClosed = false **
main_process_globals (java line: 2802)
java.lang.NoClassDefFoundError: anywheresoftware.b4a.net.FTPWrapper
at trans.capiart.sa.main._process_globals(main.java:2802)
at trans.capiart.sa.main.initializeProcessGlobals(main.java:1101)
at trans.capiart.sa.main.afterFirstLayout(main.java:85)
at trans.capiart.sa.main.access$100(main.java:16)
at trans.capiart.sa.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

thank you
 

JATAIDE

Member
Licensed User
Longtime User
Are you doing anything other than declaring the FTP object in Process_Globals?


yes i use other varibles for utilization of the program acess in the other modules


Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim utilizador ,firmaescolhida, tipoescolhido, placaescolhida, MAQUINAS,metergasoleo,menu,valordoficheiro,filenam As String
Dim reverficheiro,metergasoleox,contacondutor As Int
Dim FTP As FTP

End Sub




now created another simple program just to check and the following error

program:


Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim FTP As FTP
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("menu")

If FirstTime Then
FTP.Initialize("FTP", "xxxxxx.com", 21, "ccccccc.com", "xyz")
End If

FTP.UploadFile(File.DirRootExternal & "/Android/data/artur.capitao/malaxeurpdf/", "2005.pdf", True, "/home/ecalmodo/public_html/jataide")

End Sub




error:


Installing file.
~i:** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
main_process_globals (java line: 279)
java.lang.NoClassDefFoundError: anywheresoftware.b4a.net.FTPWrapper
at b4a.example.main._process_globals(main.java:279)
at b4a.example.main.initializeProcessGlobals(main.java:259)
at b4a.example.main.afterFirstLayout(main.java:85)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
~i:** Activity (main) Resume **

thank you one more time
 
Last edited:

JATAIDE

Member
Licensed User
Longtime User
Delete Net.jar from both the internal libraries folder and the additional libraries folder and copy it again.

Thank Erel, I just bought the entreprise version and the program already works witout crash, great version
 

GerdW

Member
Licensed User
Longtime User
Hello!

I'm B4A-Beginner and I'm full of praise for this work, not only for the programming-tool but also for the documentation around.
Now my question concerning FTP: I use the NET-Library. Downloading files and other functions work without problems, but the event-subs
"FTP_DownloadProgress" and "FTP_DownloadCompleted" are not included (provided) by the system (no reaction).

My Code:
  • Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
  • Log(ServerPath & ", Success=" & Success)
  • If Success = False Then Log(LastException.Message)
  • Msgbox("Download OK","") ' Zum Testen - For test purposes
  • End Sub

Is there anything to do, to accept these subs?

Thank you in advance
Gerd Walter
 

AscySoft

Active Member
Licensed User
Longtime User
Hi Erel and everyone
I want to send two different emails(not the same body, and not the same address and one without attachment) at once(one after another); how can I discover witch one of the emails has been sent correctly and witch one doesn't? I am having trouble with some large file being attached/ Does SMTP MessageSent could be change? Or does it display results in the same order as SMTP.Sent command was given?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there anything to do, to accept these subs?
Where is the code that initializes the FTP object?

SMTP messages are sent one after another.
If you are only sending two messages then it is safe to assume that the order of MessageSent events is the same as the order of SMTP.Send calls.
However you can always send the next message from the event and have full control over the order (it will not be slower).
 

GerdW

Member
Licensed User
Longtime User
Where is the code that initializes the FTP object?

Hi Erel,

sorry, my question was obviously unnecessary. I just saw (after a restart of my system and of cours B4A) that now all works as it should do. I can't explain it, as I did'nt change anything.

Thank you for your effort,
 

AscySoft

Active Member
Licensed User
Longtime User
Last edited:

catyinwong

Active Member
Licensed User
Longtime User
"500 I won't open a connection to 192.168.0.102 (only to 14.199.234.149)"
What does it mean??
 

catyinwong

Active Member
Licensed User
Longtime User
Now I have set the passivemode to true. And then a new error popped up:
553 Can't open that file: No such file or directory

But the destination folder is already existing on the FTP server...
 
Last edited:
Status
Not open for further replies.
Top