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

MotoMusher

Active Member
Licensed User
Longtime User
Fantastic Erel. You saved my hide. I have tested this with Gmail and Hotmail (live.com) over starttls and it works great. No issues.

I do have a question. It does not seem to matter if I set enablessl to true or false when using starttls (just testing). Does that mean providers support both simultaneously, or are you trapping the SSL if StartTLS is enabled?

Doesn't matter I guess. Just curious.

Thanks again. This is huge.
 

tango

Member
Licensed User
Longtime User
please help.

FTP library used and during initialize FTP it gives unexpectedly : app has stopped

LogCat connected to: emulator-5556
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


main_upload_click (java line: 292)


java.lang.NoClassDefFoundError: anywheresoftware.b4a.net.FTPWrapper


at b4a.example.main._upload_click(main.java:292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:59)
at android.view.View.performClick(View.java:4202)
at android.view.View$PerformClick.run(View.java:17340)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)


at dalvik.system.NativeStart.main(Native Method)
 

MotoMusher

Active Member
Licensed User
Longtime User
I use this in my apps to send pictures over SMTP. A lot of users have failures, most common symptom is with duplicate emails being sent. I have modified the code to be more stringent to avoid the dups as their submissions show on a website, but the errors continue to pile up. This happened in the old version, and also happens in the new version. Sometimes the errors vary, but the vast majority are as follows.

07/22/201320:38:40EmailFail-libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
07/22/201320:40:11EmailFail-libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
07/22/201320:40:12EmailFail-libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)

In researching, I ran across this article. I am wondering if it is applicable to the library? Not sure how I can implement a solution in my project to test. Any ideas?

http://stackoverflow.com/questions/...exception-connection-reset-by-peer-in-android

"This behavior can be disabled by setting the http.keepAlive system property to false before issuing any HTTP requests. The http.maxConnections property may be used to control how many idle connections to each server will be held."

Is this implemented, or is there any way for me to access it from the library?
 

MotoMusher

Active Member
Licensed User
Longtime User
One thing I have noticed is that I almost never get a failure over a wifi connection, which is what I use 99% of the time. Failure rate goes up based off of connection speed. I did some "in the field" testing on saturday and and had 6 out of 10 fail. 3 of the 6 had sent successfully, but had an error in the SMTP routine, and the other 3 failed to send completely. That was on a primarily 2G/Edge connection. Users on 4G connections seem to run about 20% failure rate. Attached is a sample image that generated one of the 3 err lines I posted above. Those particular pics were only 25kb in size. There is 1 line of text in the email, and a subject line of approx 20 chars.
 

Attachments

  • 1374547208000.jpg
    1374547208000.jpg
    25.3 KB · Views: 170

MotoMusher

Active Member
Licensed User
Longtime User
i am using gmail to send personally,as are some other users, but not all .

i am having problems pasting into this box from my phone error log is 5 posts up . recvfrom failed econnreset
 

MotoMusher

Active Member
Licensed User
Longtime User
Are you using Gmail?

Seems like you will need to implement a "retry" mechanism. Try to send the failed mails a few minutes later.

Yes. I am using gmail. I was resending previously, but 50% of the messages actually send, then receive the error anyway, so resending causes duplicates.

I already have another screen where the the users see their failed messages and can resend or delete, but most users are not comfortable with an app that fails 20%-50% of the time in sending an email.

Are there alternate SMTP options people have used with B4A? That may at least show a difference in failure rates perhaps?
 

Stuart McLachlan

Member
Licensed User
Longtime User
Just tried this SMTP library for the first time. There doesn't seem to be any way to set a Date Header when sending email? Emails are coming in from the application without one. Am I missing something?

(Date is a required Header for Internet Mail Format specified in RFC5322 Para 3.6 "
The only required header fields are the origination date field and
the originator address field(s).
)
 

Stuart McLachlan

Member
Licensed User
Longtime User
Do you mean that you haven't encountered a missing date, or that you are not concerned that the email goes without one?
A missing or malformed Date Header is one of the tests that many spam filters use since the RFC standard requires one in a specific format. It's absence may well result in a message being rejected as spam.

Thanks , NetExtra allowed me the insert an appropriately formatted date.

But if you are intending to update the Net library at any time in the future, can I request that it automtically inserts an appropriately formatted Date Header at the time of sending in accordance with the standard RFC 5322?
 
Status
Not open for further replies.
Top