Email services and B4A

NJDude

Expert
Licensed User
Longtime User
I've searching and I've been unable to find an email client written in B4A, my question is, B4A supports email? I've seen examples but open the device's email client, what I'm aiming at is to write an email client from scratch like K9-Mail or something like that.

Thanks
 

moster67

Expert
Licensed User
Longtime User
If you want to write an e-mail app from scratch, then you could probably use the Network-library and using standard SMTP, POP3 and IMAP-ports for comunication. There is plenty of code out there ready to convert into B4A-code for implementing above protocols.

The tricky parts might be implementing Attachment- and MIME-support. In addition, you should be aware of the fact that many mailservers these days use SSL for authentication (I don't know if the network-library supports SSL).

Of course, for sending e-mails you could use the phone-library's e-mail intent.

I've searching and I've been unable to find an email client written in B4A, my question is, B4A supports email? I've seen examples but open the device's email client, what I'm aiming at is to write an email client from scratch like K9-Mail or something like that.

Thanks
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Of course, for sending e-mails you could use the phone-library's e-mail intent.

That doesn't seem to work on all phones for what I've seen.

I'll try the network library and see how it goes.

Thanks


NOTE: Unless there is a way to send an email without the need to display the client or the user to hit SEND, I'll settle for that at the moment.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I did, very briefly, consider implementing an email client for an app I have. because as you say, sending email from Android is hit and miss at best, SSL does seem to be the sticking point and I didn't have time to investigate fully.

If you can find an email server that doesn't use SSL then there are some guides to the communication with email servers on the net. Search for 'telnet email server' or something similar and you'll find them. To implement a full email app, you'd obviously have to include SSL.

If you're trying out email intents within B4A I suggest you download K-9 email client. It seems to behave consistently and works with attachments etc. But you still need to press send.

Steve
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
The problem using a client such as K9 is that in order for my app to work I would have to instruct the user to download a 3rd party app just for one simple task, that doesn't sound right to me; in this particular case, say you have a button called REPORT or something like that and when it's clicked sends an email "in the background" no need to open a client.

I thought that on Android would be easier since it's a phone and you are connected all the time, I guess not :p
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I know, I struggled with this one too. Some might get lucky and get gmail to work, the mail client on HTC phones works OK, but needs a different intent structure. I don't have any other phones to try out.

If you're not sending attachments then you may have an easier job, Gmail should work OK. I didn't want to delay the project for an indefinite amount of time while I looked for a solution so went with the quickest route and may have to revisit it later.

Steve
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I hear you, I also have an HTC and a LG Optimus V, and they behave differently, but not the way I need it, yup, back to the drawing board.

I need to send attachments too, forgot to add.
 
Upvote 0

sortec.nick

Member
Licensed User
Longtime User
Hello, I wonder if you can help me.

What is the B4A equivalent to the following Java code:

B4X:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.setType("text/plain");

emailIntent.setClassName("com.android.email", "com.android.email.activity.Welcome");

emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(emailIntent);


My aim is to start the email client as the above would in Java.
 
Upvote 0

sortec.nick

Member
Licensed User
Longtime User
Hello NJDude.

I appreciate your link, but I think you may have misinterpreted my aim as that post details how to start a MailTo intent.

I can already do this with the following:

B4X:
Sub MailTo(StrAddress As String, StrSubject As String, StrBody As String)
    Dim StrMethod As String = "Sub StartEmailClient(StrSubject As String, StrBody As String)"
    Try
        Dim StrUri As String
        StrUri = "mailto:" & StrAddress & "?subject=" & StrSubject & "&body=" & StrBody
 
        Dim Intent As Intent
        Intent.Initialize(Intent.ACTION_VIEW, StrUri)
 
        StartActivity(Intent)
 
    Catch
        'If BlnLoudExceptions Then CdException.Show(StrClass, StrMethod, LastException)
        LogColor(LastException & " - " & StrMethod, Colors.Magenta)
    End Try
End Sub

What I need to do is:
  1. Understand how to convert a Java written intent to it's B4A equivalent
  2. In my specific example, to open the inbox of the mail client from my app.
Thank you
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I've searching and I've been unable to find an email client written in B4A, my question is, B4A supports email? I've seen examples but open the device's email client, what I'm aiming at is to write an email client from scratch like K9-Mail or something like that.

Thanks
Hey NJ, long time bud, i know this is a very old post, but i wrapped a library which can be used to develop an Email Client app, however i've hit a roadblock and i can't seem to find a solution, i've beginning to think i have finally found a limitation in B4A, the library works great, i'm able to have a user login using oAuth2 and retrieve all mailboxes and fetch the emails, also send emails, fetch attachments etc.. basically the whole 9 yards, however i have been struggling with checking for new incoming emails in a Background Service, according to what i have been reading you can not schedule a service to run every 30 seconds unless you create a foreground service, which would show a notification and obviously this is something that I know for a fact users would hate to see.

Anyhow, if you are interested we can chat and maybe we both can come up with a solution, i can share the library with you so you can play around with it and maybe we both can figure out a way to make this work, as I mentioned this library has everything we would need to build an Email Client app.

Hope to hear back from you, Take care bud.

Walter
 
Upvote 0
Top