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

MotoMusher

Active Member
Licensed User
Longtime User
This library is great. I have a question on SMTP content-type.

I believe attachments are being sent as application/octet-stream. It works fine, but one of the services that users are using wants image/jpeg and it is discarding octet-stream messages.

Any ideas how to get around it? SMTP message in my case is always just a post of an image taken with the camera I wrote.
 

rboeck

Well-Known Member
Licensed User
Longtime User
GermanUmlaute with SMTP library

i found out, that 'umlaute' in smtp1.sender are not handled correct, but umlaute in body and subject works without any problems.

The sender name should be: Böck, but the receiver gets: Böck

Any tipps to convert this string?

Greetings
Reinhard
 

rboeck

Well-Known Member
Licensed User
Longtime User
Yes; i want to send with my real name;here is the code:

B4X:
SMTP1.Sender = Main.Setup.Get("Name")  'real name with umlaute..
SMTP1.To.Add(EditText5.Text)                   ' email adress

Greetings and thanks for your help!
Reinhard
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi Erel,

i never used such a futuristic library, which date is in the future! ;)

Back to my problem: In Outlook can see now the 'Umlaute', but it is not the usual style:

This is the line on top of the message:
Reinhard Böck <=?UTF-8?Q?Reinhard_B=C3=B6ck?=>

A message sent to myself look like:
Reinhard Böck <[email protected]>

On the tablet i see the incoming mail and in the short preview i see only ""< for a short time. Inside gmail on handy and tablet now i see everything correct.
Maybe ic could convert the sender field and replace the umlaute with something ...

Many thanks for your work!
Reinhard
 

MotoMusher

Active Member
Licensed User
Longtime User
Has anyone else gotten this to work with Hotmail or me.com over SMTP?

Gmail users and others are fine, myself included. My hotmail users and me.com are having problems.

I signed up for a hotmail.com account to test and get the following error.

SendTestEmail-javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x140f1a0: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:683 0x40193cf5:0x00000000)


Setup is [email protected]
smtp.live.com
ssl enabled
port 587

I was not trapping the me.com (icloud.com) errors in the current release and don't have an account to check there.

In a little research it appears that "starttls" may be different than SSL/TLS? I don't know enough to comment. Issue 20175 - android - Mail setup issues - Android - An Open Handset Alliance Project - Google Project Hosting


Any help is appreciated.
 

MotoMusher

Active Member
Licensed User
Longtime User
It does pass the validation step for incoming and outgoing mail in the android app with the letter and @ wax seal logo. It also sends and receives email. The app has choices for both SSL and TLS and it is picking TLS on the autosetup not SSL.

Most cases where users have a failure in my app the provider specifies TLS.

My app still fails with same setup.
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Seems to me that TLS is not supported for now. Is there a chance this may change soon? Yahoo servers strictly use TLS since some time and I have to change my app accordingly.
 

GMan

Well-Known Member
Licensed User
Longtime User
Hi Erel,
i always got an error in the log when sending an email:
B4X:
false
java.net.UnknownHostException: smtp.gmail.com

all parameters are correct, the email soft(outlook) connects well and works fine.

I will send a body with some contents of some EditText's like this:
B4X:
SMTP.Body = Name.Text & CRLF & Surname.Text & CRLF

Any suggestions for this ?
 

MotoMusher

Active Member
Licensed User
Longtime User
GMan Your problem may be with enable ssl, or the port. Port should be 465 with UseSSL true

Here's my code that works fine with this library with the exception of providers requiring StartTLS (yahoo.com, me.com, outlook.com, live.com etc)


B4X:
Dim SMTP As SMTP
Dim MyFilePath As String
Dim DirName As String = "Something"
MyFilePath = File.DirRootExternal & "/" & DirName & "/SomethingElse/"
SMTP.Initialize(MyAuth.CamSMTPServer, MyAuth.CamPort, MyAuth.CamMyEmail, MyAuth.CamMyPass, "SMTP")
SMTP.UseSSL = MyAuth.CamSSL 'True 'Gmail requires SSL.
SMTP.To.Add("[email protected]")
SMTP.To.Add(MyAuth.CamMyEmail)
SMTP.Subject = "TestMessage"
SMTP.HtmlBody = False
SMTP.AddAttachment(File.DirAssets, Main.Graphic)   
SMTP.Send

Also, you may want to make use of .trim (surname.text.trim). Sooner or later it will bite you if you don't. This is especially true for when setting port numbers, and email addresses, and smtp servers and passwords...
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
Thx Erel,

just solved the "problem" :D
was sitting outside with my notebook and it lost connection (i tested this time with the Virtual Device), so email couldn't work.

So, everything is fine - but finest of all is your lib :sign0188:
 

sktanmoy

Active Member
Licensed User
Longtime User
Starttls

I failed to understand how to use STARTTLS after reading first post? smtp.StartTLSMode = ture will work? Or anything else?
 
Last edited:
Status
Not open for further replies.
Top