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. Kwame Twum

    Kwame Twum Active Member Licensed User

    so Erel, isn't there anything I can do about it? :)
    Or I'll have to work on a different server...
    Last edited: Dec 27, 2013
  2. Erel

    Erel Administrator Staff Member Licensed User

    Seems like your server uses a SSL protocol not supported by the device.
    Kwame Twum likes this.
  3. sorex

    sorex Expert Licensed User


    How come this library is not included in the B4A install?

    It's an "official one by you"
    Valentino likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Not all official libraries are included in the IDE. This library is based on an Apache licensed project. While it is possible to include it in the IDE I preferred not to.
  5. sorex

    sorex Expert Licensed User

    ok, I can live with that.

    it's just confusing to have net and network.

    for example I added network and started typing

    dim ftp as ftp

    and wondered why it resulted in an error, then I spotted that net was a replacement for the ftp lib
    and the ftp lib was an additional/seperate lib than the network lib.
  6. Erel

    Erel Administrator Staff Member Licensed User

    V1.50 is released. It adds support for FTP Over SSL explicit mode (implicit mode was already supported by setting UseSSL to true).

    It also includes a new object type named CustomTrustManager. CustomTrustManager allows you to load certificates from files and also to create a trust manager that accepts all certificates without checking them.

    For now it can only be used with FTP.

    To use it you should initialize a CustomTrustManager object and then set it with FTP.SetCustomSSLTrustManager.
  7. biometrics

    biometrics Active Member Licensed User

  8. Erel

    Erel Administrator Staff Member Licensed User

    I haven't checked it.
  9. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    with the SSL and TLS I get an TimeOut Error:
    Try to send on: 587, SSL: false, TLS: true
    TOtrue count: 1 = hubert.brandel@gmx.de
    After Send ...
    SMTP send: false
    java.net.SocketTimeoutException: Connection timed out
    with 25 and both ssl and tls vars to false I get this
    Empty writer returned: 
    503 Bad sequence of commands.
    You must specify the recipients of a message before you can send it
    so it looks like the DEBUGGER MODE could send the email, but the SMTP Server does not response on SSL / TSL ...
    and the responce on port 25 is an error message from the server ... is this right ?

    But what does he want to tell me with the bad sequence ?

    'Activity module
    Sub Process_Globals
    Dim sDir As String = File.DirRootExternal     ' file attachement from ...
        Dim sFile As String = "HB-PDF.pdf"            ' name ...
        Dim sTo As String = "TargetEmailAdress@xyz.de"
    ' email über SMTP Server ... hierfür braucht man eine Internetverbindung und Klaus sollte eine eMail-Sendeadresse auf seinem Server anlegen.
        Dim SMTP As SMTP
    Dim sServer As String = "mail.server.de"  ' the SMTP Server
        Dim sSender As String = "ProgName@MySite.de" ' each app has its own eMailAdress to send from ...
        Dim sFrom As String = sSender
    Dim sPW As String = "..." ' the right password
        Dim iPort As Int     = I want to change this later in the APP

    End Sub

    ' normaly this code should be here ...

    Sub Activity_Create(FirstTime As Boolean)   
    If FirstTime Then
         Label1.Text = 
    "eMail an: " & sTo
         Port25.Checked = 
         iPort = 
    SMTP.Initialize(sServer, iPort, sFrom,sPW,"SMTP")
    SMTP.StartTLSMode = False
    SMTP.UseSSL = False
    End If    
    End Sub
    but than I can't change the port later in the app, am I right ?
    so I removed the init from activity_create to the button_click event ...

    Sub Send_Click
    If File.Exists(sDir,sFile) Then ' no file, no eMail
         ToastMessageShow("PDF senden (" & iPort & ")...",False' this shows the right port
         SMTP.Initialize(sServer, iPort, sFrom, sPW, "SMTP" ) ' look good in debugger
         If iPort = 25 Then
    SMTP.UseSSL = False
    SMTP.StartTLSMode = False
    If iPort = 465 Then
    SMTP.UseSSL = True
    SMTP.StartTLSMode = False
    End If   

    If iPort = 587 Then
    SMTP.UseSSL = False
    SMTP.StartTLSMode = True
    End If   
    End If   
    Log("Try to send on: " & iPort & ", SSL: " & SMTP.UseSSL & ", TLS: " & SMTP.StartTLSMode )
    SMTP.Sender = sSender ' no change if I remove this line 
    Log("TO: " & SMTP.To.IsInitialized & " count: " & SMTP.To.Size & " = " & SMTP.To.Get(0) ) ' The log say, that I have 1 TO adress and it is right.
         SMTP.Subject = "Test eMail mit PDF Anhang"
    SMTP.Body = "Diese PDF habe ich gerade vom Smartphone erzeugt ;-) "
    Log("After Send ...")     
    ToastMessageShow("PDF fehlt !",False)
    End If
    End Sub

    Sub SMTP_MessageSent(Success As Boolean)
    Log("SMTP send: " & Success )
    If Success Then
    ToastMessageShow("PDF wurde versandt !",True)
    ToastMessageShow("eMail Fehler !",True)
    End If   
    End Sub
    the log says this with 25 (no SSL/TLS)

    ...Try to send on: 25, SSL: false, TLS: false
    TOtrue count: 1 = hubert.brandel@gmx.de
    After Send ...
    SMTP send: false
    java.lang.RuntimeException: Empty writer returned: 
    503 Bad sequence of commands. You must specify the recipients of a message before you can send it
    I have cut & paste the code from some examples and could not find what is missing ;-(

    PS: NET 1.50 ... just loaded into the ExtraLib SubDir.
  10. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    the same result if I put the init inside of CREATE
  11. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    very strange, if I use my own GMX.DE email account with ...
    iPort = 465
    SMTP.UseSSL = True
    SMTP.StartTLSMode = False

    than the eMail is send correct and true will come back.
    With ...
    iPort = 587
    SMTP.UseSSL = False
    SMTP.StartTLSMode = True

    same error 503 ...
  12. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    I found a SMTP Error PDF with this info:

    503 now means that your server request a authentication ... but still use 25.
    Is there a setting to tell SMTP-Lib to authenticate ?
  13. Erel

    Erel Administrator Staff Member Licensed User

    It will always try to authenticate. Are you sure that the server expects an SSL connection?
  14. warwound

    warwound Expert 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?


  15. Erel

    Erel Administrator Staff Member Licensed User

    I will send you the source. I'm still investigating an issue related to the new features. Will send you when it is ready.
    warwound likes this.
  16. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    This server (with the 503 message and 25 as port) does NOT want a SSL connection, because normaly I use a Win32 bit EXE as CGI-EXE and send with the "ASINET" LIB from my win32 bit compiler. This LIB does not support SSL or TLS, just login with name and password. Its a hosteurope web server.
    Function SendAsinet(aEmpfaenger,cBetreff,cText,cProgPfad,aAttachFile,cAntwortAdresse) 
    ' my function
      LOCAL oSmtp  := SMTPClient():new( GetSmtpServer(),,, oLog, 
    2 )
      LOCAL oSender  := MailAddress():new( 
    "xxxxx@yyyy.de" )
      LOCAL oMail  := MIMEMessage():new()

      oMail:setFrom  ( oSender  ) // 
      oMail:setSubject  ( cBetreff  ) // 
    "Test eMail ..."
      oMail:setMessage  ( cText  ) // just the body text
      aeval(aEmpfaenger, {|cEmp| oMail:addRecipient(MailAddress():new(cEmp) ) 
    }) ' adds all TO adresses
      oMail:addHeader( "Date", TimeStampSMTP() ) ' need to correct an error with date 
      if ! aAttachFile = NIL
         aeval(aAttachFile, {|cFile| oMail:attachFile( cFile ) })

      IF oSmtp:connect( sUserName, sPassword ) ' fix from a ini file
         IF oSmtp:send( oMail )
             lOK := .t.
             ? "Message sent"
             ? "Unable to deliver message"
         ? "Unable to connect to mail server"
    this LIB just connect with (sUserName, sPassword), no PORT (means standard), no SSL / TLS ... in both cases this server does not responde on SSL / TLS connections, but give this 503 Error back with 25 (try) connection.
  17. Erel

    Erel Administrator Staff Member Licensed User

    So both UseSSL and StartTLSMode should be false. Anyway if it doesn't work then please start a new thread for this question.
  18. enemotrop

    enemotrop Member Licensed User

    Is it possible to append a line to a text file using this library? Like using the APPE ftp command...

    Syntax: APPE remote-filename
    Append data to the end of a file on the remote host. If the file does not already exist, it is created. This command must be preceded by a PORT or PASV command so that the server knows where to receive data from.
  19. Erel

    Erel Administrator Staff Member Licensed User

    See FTP.SendCommand.
  20. enemotrop

    enemotrop Member Licensed User

    Thank you Erel!
Thread Status:
Not open for further replies.
  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