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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Aug 17, 2011.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    All you need to do is set StartTLSMode = True.

    If you are using Gmail then you should change the port from 465 (ssl) to 587.
     
  2. MotoMusher

    MotoMusher Active Member Licensed 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.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    UseSSL value is ignored if StartTLS is set to True.
     
  4. tango

    tango Member Licensed 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)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please do not post duplicate questions.
     
  6. MotoMusher

    MotoMusher Active Member Licensed 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?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    The connection is handled internally by the Apache library. How large are the mails you are sending?
     
  8. MotoMusher

    MotoMusher Active Member Licensed User

    typically between 100 and 300kb
     
  9. MotoMusher

    MotoMusher Active Member Licensed 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.
     

    Attached Files:

  10. Erel

    Erel Administrator Staff Member Licensed 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.
     
  11. MotoMusher

    MotoMusher Active Member Licensed 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
     
  12. MotoMusher

    MotoMusher Active Member Licensed User

    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?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    No. Note that the suggestion in the link you posted is not relevant as the SMTP library doesn't keep any connection alive.

    Which port of Gmail are you using?
     
  14. MotoMusher

    MotoMusher Active Member Licensed User

    Using both 465 and 587 toggling back and forth looking for cause/effect. Seems to be consistent between both ports.

    Thanks for the confirmation on the connections.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    It might be some "spam" protection applied by the mobile provider to avoid sending many mails. Consider merging the list of mails to a single mail.
     
  16. Stuart McLachlan

    Stuart McLachlan Member Licensed 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).
    )
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    I haven't encountered any issue with a missing date.

    You can however add headers with this library: [lib] NetExtras
     
  18. Stuart McLachlan

    Stuart McLachlan Member Licensed 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?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    I meant that the Net library was tested with most common mail servers and it worked fine. However I agree that it should be fixed.
     
  20. boten

    boten Active Member Licensed User

    Bug in SMTP? BCC recipients can see all other BCCs
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice