1. Download the free trial version

Library New Net library - Android FTP, SMTP and POP3

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

  1. Erel

    Erel Administrator Staff Member Licensed User

    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 you to directly connect to SMTP mail servers and send mails, including Html messages and attachments (more complicated than it may sound ;))
    POP3 - Allows you 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 internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries

    The documentation which includes examples is available here: Basic4android - Net

    Mails can be a very good and reliable communication channel for Android devices which are likely to not always be connected.
    It allows you to take advantage of the mailing technology which is one of the most popular and veteran Internet technology.

    V1.53 - Fixes an issue with FTP.CloseNow and SSL connections.

    V1.52 - Adds support for different types of authentication methods (SMTP): http://www.basic4ppc.com/android/fo...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.basic4ppc.com/android/fo...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:
    Code:
    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.

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    If FirstTime Then
          smtpClient.Initialize(
    "smtp.gmail.com"587"xxx@gmail.com""yyy""SmtpClient")
          smtpClient.StartTLSMode = 
    True
       
    End If
    End Sub
     

    Attached Files:

    • Net.zip
      File size:
      184.4 KB
      Views:
      802
    Last edited: May 27, 2014
  2. ZJP

    ZJP Active Member Licensed User

    Yessssssss !!!!!!! :sign0060:
    Thx

    JP
     
  3. moster67

    moster67 Well-Known Member Licensed User

    Wow Erel! Many thanks for this. :icon_clap:

    I am in the office now so I cannot test it. I noted that SMTP permits attachments and there is also SSL-support. Wonderful! :sign0060:

    As to POP3, when you say
    are you intending attachments and MIME-handling?
     
  4. Kiffi

    Kiffi Active Member Licensed User

    Thanks a lot, Erel!

    :sign0098:

    Greetings ... Kiffi
     
  5. Brad

    Brad Active Member Licensed User

    you rock man!:sign0060:
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I actually tried several solutions before releasing this library, however none of them worked properly. The case with POP3 is that the general problem of supporting all the possible encodings and messages is very complicated.
    However using POP3 to receive messages with a known format is much simpler.

    If there is interest I can write a module that will help with saving attachments and with the headers.

    As I wrote in the first post I think that the POP3 is a very important feature as it is a reliable method to send information to devices.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. dealsmonkey

    dealsmonkey Active Member Licensed User

    Kwame Twum likes this.
  9. peacemaker

    peacemaker Well-Known Member Licensed User

    Good news !
    Erel, is it hard to add NNTP protocol ? :)
     
  10. Inman

    Inman Well-Known Member Licensed User

    Just the library I was looking for. SMTP library makes it really easy to send emails, that too with attachments.

    One request. Is it possible to add IMAP to this library? IMAP enables the user to download certain folders (or labels) instead of downloading the whole thing. Implementing an attachment download feature might be possible as well. Google has a documentation page on IMAP extensions for Gmail, but none of that makes sense to me.
     
  11. alwaysbusy

    alwaysbusy Active Member Licensed User

    never receive any messages

    Hi Erel,

    I'll try to get the .net lib working. I do not get any errors but in the ListCompleted() event the Messages is always empty although there are mails in my inbox.

    I've activated the pop download in GMail (see images.zip).

    In my Desktop app (RealBasic) I get the mail from the inbox.

    Code:
    'Activity module
    Sub Process_Globals
       
    'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
       Dim pop As POP3
    End Sub

    Sub Globals
       
    'These global variables will be redeclared each time the activity is created.
       'These variables can only be accessed from this module.
       
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       
    If firstTime Then
          POP.Initialize(
    "pop.gmail.com"995"my@gmail.com""mypwd""pop")
          POP.UseSSL = 
    True 'Gmail requires SSL.
       End If
       pop.ListMessages
    End Sub

    Sub pop_ListCompleted (Success As Boolean, Messages As Map)
            
    Log ("Success: " & success)
       
    If Success = False Then
          
    Log(LastException.Message)
       
    Else
          
    'download all messages
          'change last parameter to True if you want to delete the messages from the server
          Log ("messages: " & Messages.Size)
          
    For i = 0 To Messages.Size - 1
             pop.DownloadMessage(Messages.GetKeyAt(i), 
    False)
          
    Next      
       
    End If
       pop.CloseEnd 
    Sub

    Sub pop_DownloadCompleted (Success As Boolean, MessageId As Int, MessageText As String)
       
    If Success = False Then
          
    Log(LastException.Message)
       
    Else
          
    Log(MessageId)
          
    'Parse the mail
          Dim m As Message
          
    Dim s As String
          s = MailParser.GetSubject(MessageText)
          
    If s.Contains("P000001"AND s.Contains("[OUT]"Then
             m = MailParser.ParseMail(MessageText, 
    File.DirRootExternal)
          
    End If
          
    Log(m)
       
    End If
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
    The result in the log:

    Code:
    ID[0]=0(0) Dn(0=>1)
    Dsptch > Window{
    48602558 com.android.packageinstaller/com.android.packageinstaller.InstallAppProgress paused=false}
    Dsptch > Window{
    48602558 com.android.packageinstaller/com.android.packageinstaller.InstallAppProgress paused=false}
    ID[
    0]=0(0) Up(1=>0)
    Starting activity: 
    Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.AB.OneTwoANWork/.main }
    Start proc com.AB.OneTwoANWork 
    for activity com.AB.OneTwoANWork/.main: pid=8075 uid=10168 gids={10153003}
    Zygote: pid 
    8075 has INTERNET permission, then set capability for CAP_NET_RAW
    ** Activity (main) Create, isFirst = 
    true **
    ** Activity (main) Resume **
    Using factory org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl@4006ef08
    Displayed activity com.AB.OneTwoANWork/.main: 
    1047 ms (total 1047 ms)
    Default buffer size used 
    in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
    Default buffer size used 
    in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
    [B]Success: 
    true[/B]
    [B]messages: 
    0[/B]
    Timer 0x3->0x3|0x0
    GC_EXPLICIT freed 
    272 objects / 17424 bytes in 136ms
     

    Attached Files:

  12. Erel

    Erel Administrator Staff Member Licensed User

    I've just tried similar code with my Gmail account and it worked properly. Try sending a new message to your account and then run the Android program.
     
  13. fargoz

    fargoz Member Licensed User

    problem compile .net library

    [ompiling code. 0.14
    Generating R file. 0.00
    Compiling generated Java code. 2.17
    Convert byte code - optimized dex. Error
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: already added: Lorg/apache/commons/net/DatagramSocketClient;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
    at com.android.dx.command.dexer.Main.processClass(Main.java:372)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
    at com.android.dx.command.dexer.Main.access$400(Main.java:59)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
    at com.android.dx.command.dexer.Main.processOne(Main.java:313)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
    at com.android.dx.command.dexer.Main.run(Main.java:185)
    at com.android.dx.command.dexer.Main.main(Main.java:166)
    at com.android.dx.command.Main.main(Main.java:90)
    1 error; aborting
    Standard dexer.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Which libraries did you reference?
    Can you upload your project?
     
  15. fargoz

    fargoz Member Licensed User

    I found the solution .., thank you very much

    I found the solution .., thank you very much

    The problem was that I had the library, ABFTP, remove them, and make again for communications with the new library. net and it works perfect.

    Many thanks, Erel, are excellent administrator.


    google traductor.
    only spanish.
     
  16. dfsantos

    dfsantos Member Licensed User

    I am also interesed
    it is possible??
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    I plan to add it in the future.
     
  18. dfsantos

    dfsantos Member Licensed User

    Thanks for you work :sign0060::sign0060::sign0060:
     
  19. Hubert Brandel

    Hubert Brandel Active Member Licensed User

    Hi,

    this LIB is called NET.* in the library dir I have a NETWORK.* do we have to rename the file, or is it different ?

    OK, I just see NET -> SMTP, NETWORK -> Sockets, so I will need both ;-)
     
    Last edited: Oct 9, 2011
  20. Erel

    Erel Administrator Staff Member Licensed User

    As you saw these are two different libraries. Network is for TCP / UDP communication and Net library is an implementation of several protocols: FTP, SMTP and POP3.
     

Share This Page

Loading...