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. Fabrice La

    Fabrice La Active Member Licensed User

    Hi

    I created this program but the system never goes to SMTP1_MessageSent(Success As Boolean).
    I confirm that android sent correctly the message but never goes to this event, no log(Success) ...
    Code:
    Sub Activity_Resume
       SMTP1.Initialize(tmpST(
    0), tmpINT, tmpST(1), tmpST(3), "SMTP")
          
    If tmpST(4) = "true" Then
               SMTP1.UseSSL = 
    True 
          
    Else
             SMTP1.UseSSL = 
    False
          
    End If
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub btnEnvoyer_Click
       
    If File.Exists(File.DirDefaultExternal, "configEmail.ndf"Then
          SMTP1.To.Add(edbDestinataire.Text)
          SMTP1.Subject = edbSujet.Text
          SMTP1.Body = edbBody.Text
          
    If cbFrais.Checked Then
             SMTP1.AddAttachment(
    File.DirDefaultExternal, "file1")
          
    End If
          
    If cbIKM.Checked Then
             SMTP1.AddAttachment(
    File.DirDefaultExternal, "file2")
          
    End If
          SMTP1.Send
       
    Else
          
    Msgbox(Main.trans.GetText("Serveur de mail non configuré"), Main.trans.GetText("Attention"))
       
    End If
       
    End Sub

    Sub SMTP1_MessageSent(Success As Boolean)
        
    Log(Success)
        
    If Success Then
            
    ToastMessageShow("Message sent successfully"True)
        
    Else
            
    ToastMessageShow("Error sending message"True)
            
    Log(LastException.Message)
        
    End If
       
    activity.Finish
    End Sub
     
    Last edited by a moderator: Oct 12, 2011
  2. Erel

    Erel Administrator Staff Member Licensed User

    The last parameter of Initialize method is the EventName. If you set it to "SMTP" then the sub name should be: SMTP_MessageSent and not SMTP1_MessageSent

    I recommend you to initialize SMTP in Activity_Create instead of Resume.
     
  3. hanvas

    hanvas New Member Licensed User

    Two Apps, one Service, one Problem

    Hi,

    dont know if this is the right place, it seems to be more a "service" question

    At time i develop an Inhouse Application. The App send Informations about the Position, the Weight, Time, the arrival at a customers adress , the pickup or delivery of unspecified goods and somthing else.

    The Apps sends their Information as a Text File to a FTP Server. Every two Minutes the Apps poll a directory on the Ftp Server an retrieves a List of Files to see if there are messages for the Driver or other important things available. During this process the App sends also same status informations.

    I do this inside a service, to get not interrupted by the os. Even this works normaly fine.

    Everything seems to run fine up to now.

    I extendet the App starts Google Maps for Navigation via an intent. So when the pickup or delivery at a customers is finished, the driver presses a button. This sends the information about the departure to our server and starts Google Maps via an Intent to get navigated to the next customer. As of the moment where google maps is started and the topmost windows - the sending and retrieving of seems to be stopped. The Service i use to handle seems to sleep. It go to live again when i stop the google maps.

    What can I do ?

    Thanks

    Ha-Joe
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  5. peacemaker

    peacemaker Well-Known Member Licensed User

    NNTP is also needed....
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    V1.20 was uploaded to the first post. This update adds the FTP.SendCommand which allows you to issue any FTP command.
     
  7. peacemaker

    peacemaker Well-Known Member Licensed User

    Thanks, Erel. If you are updating this lib, please, try to support NNTP protocol, at least some main base possibilities (receive X latest posts, send a post with an encoding).
     
  8. vb1992

    vb1992 Well-Known Member Licensed User

    I was testing the FTP with:


    Dim FTP As FTP

    FTP.Initialize("FTP", "FTP.secureftp-test.com", 21, "test", "test")

    FTP.List("/")



    It never ends up getting to

    Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Are you testing it on the emulator or a real device? The emulator doesn't behave correctly in this case.
     
  10. vb1992

    vb1992 Well-Known Member Licensed User

    Correct:

    Bluestacks App Player for Windows PC

    Doesn't work.

    Moved it to my phone, and it worked.

    Wow, that was a nice few hours wasted.
    *edit: just taught me not to use blue stacks as my primary app player/tester

    **edit 2: Btw, the thing that threw me off, was I was actually able to send this command: FTP.SendCommand("pwd","")
    and it returned back a result in bluestacks... that's what threw me off, not getting the file listing...


    Thanks!
     
    Last edited: Nov 13, 2011
  11. Harris

    Harris Well-Known Member Licensed User

    SMTP Error

    I download net 1.2 three times.... Checked declaration and code...
    I get a compile error: "Input string was not in a correct format" on SMTP.Initialize.

    I used the exact code from the example as well as my own. I have no idea what it is barking about.... It all looks so simple.

    Any body had success using SMTP or had the same issue??

    Thanks
     
  12. Harris

    Harris Well-Known Member Licensed User

    Update.
    Seems copying and pasting code from a pdf can introduce characters (like spaces and tabs) that you can't see in the IDE and throws it for a loop when compiling. Removed the crap it it all compiles... Thank heavens....
     
  13. Harris

    Harris Well-Known Member Licensed User

    I have the same issue now... it never fires the event after SMTP1.send. Last param of Init is "SMTP1" and event is SMTP1_MessageSent.....

    In the Code Mod declared SMTP1 as SMTP in Process_Globals.... (all code for sending mail is in the code mod)


    :BangHead:
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Code modules cannot handle events. See this tutorial for more information: Static Code Modules
    The event sub should be located in the activity or service that calls the method in the code module that sends the mail (the event sub can call a code module method).
     
  15. Harris

    Harris Well-Known Member Licensed User

    Thanks Erel, I knew that..:signOops: some time ago...

    note to self: remember what code modules can handle waste less of every bodies time.
     
  16. Harris

    Harris Well-Known Member Licensed User

    Ok, moved the event to activity mod and now send mail by SMTP.

    Process:

    I Init the SMTP object.
    I take records from a table that have NOT been sent (SentDate = 0).
    For each record, I extract a PDF from the blob to a file on disk - This is the attachment.
    I send the mail (which does make it to the recipient - me) .
    Once I receive confirmation from the event (Success = True), I update the associated record's SentDate with Now. I also delete the attachment pdf file from the disk to clean up.

    The problem is that 10 records (mails) get sent in under 1 second (is this the non-blocking of which you speak?). When in actuality, these mails are que'd up and some underlying process is actually sending them. I have no idea if they did (actually) get sent - or not? There is no Progress (bar) on how each is being handled. In fact, if I drop the wifi connection, I get success results for all when some or all have not been sent.

    However, if I try to start a send session without a wifi connection, I get "no sever found" - which is quite logical and expected.

    How can I get verification that each mail was actually sent? I cannot correctly update the table without knowing the mail DID make it out the door.

    Thanks so much...
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    There was a bug in SMTP. Mails should not be sent at parallel (it was not enforced correctly). I've fixed it for the next update of Net library. However the best approach is to wait for one message to be sent and then send the next one in MessageSent event.
     
  18. Harris

    Harris Well-Known Member Licensed User

    Yes, waiting for messagesent is the approach I am trying - however Success is all I have to go on which happens immediately after issuing send (if a server is present). There is no way my mail and its' (rather larger) attachment get sent immediately. I was hoping for the ack after the mail (in its' entirety) had been accepted by the server - or would this be considered blocking - holding everything up waiting for a response from the server - or determining when the last byte of the message went out?

    Thanks Erel
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that the event fires before the mail is sent? I've checked the code and it looks correct. The event is only raised after communication is done.
     
  20. Harris

    Harris Well-Known Member Licensed User

    Geez Erel, now I can't get it to send at all... Didn't change anything and now it reports Authenticaion required - SSL is True... (SMTP1.UseSSL=True). I will let you know when I can get past this.... Thanks

    I sent mail to support for a copy of 1.8 btw
     
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