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,063
Last edited:

fabio borges

Member
Licensed User
Longtime User
FTP Rename

Hi everybody,

I'm trying to rename a file with FTP lib but I cant.

I've used:

FTP.SendCommand("rename","myfile.tmp myfile.mps")

It dosent work.

Could somebody help me?

Thanks
 

fabio borges

Member
Licensed User
Longtime User
Solved

Worked that way.....

FTP.SendCommand("RNFR","myfile.tmp")
FTP.SendCommand("RNTO","myfile.mps")


Hi everybody,

I'm trying to rename a file with FTP lib but I cant.

I've used:

FTP.SendCommand("rename","myfile.tmp myfile.mps")

It dosent work.

Could somebody help me?

Thanks
 

diego

Member
Licensed User
Longtime User
Yes, I do. After one minute or so.

If I choose "Wait" it freezes again (if there is still no coverage)
 

diego

Member
Licensed User
Longtime User
I've tried this:

adb shell
$ cd \data
cd \data
$ chmod 777 anr
chmod 777 anr
Unable to chmod anr: Operation not permitted
$ ls
ls
opendir failed, Permission denied
$ ls data
ls data
opendir failed, Permission denied
$ ls anr
ls anr
traces.txt
$ pull traces.txt
pull traces.txt
pull: permission denied
 

diego

Member
Licensed User
Longtime User
Finally I could copy traces.txt to sdcard with "cat traces.txt > /sdcard/traces.txt"

see attached
 

Attachments

  • traces.zip
    4.4 KB · Views: 276

diego

Member
Licensed User
Longtime User
:sign0148: Please forget last posts, I had a bad loop and that was the cause.

:signOops:

at least I learned how to get traces.txt...
 

Evadman

Member
Licensed User
Longtime User
Also make sure not to test FTP with the emulator. It doesn't work properly.

Posting this here because this is the NET/FTP thread, so this may help someone else with this problem.

I recommend that stuff like this (doesn't work on emulator) be posted in the first post in a thread or somewhere easy to find in the documentation. Maybe I missed it and it's there, but the only place I saw it was buried in a thread. I spent the last week trying to figure out what was wrong with my program, company firewall, external firewall, or network to not allow posting a file to an FTP server when I tested from an emulator, because all I have is an emulator.

I got this cryptic message in the log:
D/SntpClient(75): request time failed: java.net.SocketException: Address family not supported by protocol
which occurs about 20 seconds after trying to run the attempt, so it was difficult to tie back to the ftp attempt and not some other application on the phone. The FTP.UploadFile failed completely silently. The UploadProgress and UploadCompleted events never fire, so I couldn't figure out what was happening by pulling LastException.Message on those events. Sometimes I would get a 0k file on the FTP, other times, a connection attempt wouldn't be seen on the FTP server.

I stopped reading the thread above because a few posts before that quote, there is a comment stating that there is a new library (NET replacing FTP). It took me a week to accidentally stumble upon the 'does not work in emulator' note on the 2nd page.

By the way, I am still not positive that the issue is actually caused by the emulator. It is possible I have an issue somewhere that I can't find due to not having an android device. I guess I won't know until my program goes to production on Friday.

By the way, besides this one documentation thing, I am very happy with B4A overall. This isn't the thread of praise probably, but I'm posting it here anyway. B4A is great and the documentation is quite good.
 

fisray

Member
Licensed User
Longtime User
TLS protocol

Hello everybody,

I have installed the library and created the SMTP function to send e-mails.
I tried with my own devide and it works like a charm.
This is really a beautiful piece of code, many thanks.

However, when I sent the application to the end user, the e-mail doesn't work.
He told me that he is using TLS.
I found that SSL is supported for Google but I cannot find anything concerning TLS.
My knowledge in this area is so big that I even don't know what is TLS.

My question is: is there a way to get TLS working? And how?

Many thanks in advance,
Raymond
 

fisray

Member
Licensed User
Longtime User
Hello Erel,

In fact after I posted my message, I made some researches and found some info.
I came to the same idea of setting UseSSL to true but also to select a different port.
I am currently changing the application and I will send the new version for test.
I wil keep you posted on the results.

Thanks again,
Raymond
 

fisray

Member
Licensed User
Longtime User
Hello Erel,

We tried with UseSSL = true and with the ports 465 and 587.
Unfortunately it doesn't work.

But don't spend to much time on this because they can use Gmail and this works very well.

Thank you again for this nice library.
Raymond
 

ukimiku

Active Member
Licensed User
Longtime User
What licensing conditions is the Net library subjected to? I read that someone speculated that the SMTP portion of the Net library was taken/adapted "from the Apache Commons Net project, with the Apache 2.0 license" in its wake. Is that correct?

Thank you.

Regards,
 

ukimiku

Active Member
Licensed User
Longtime User
Thanks.
 
Status
Not open for further replies.
Top