Android Question send email using gmail

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

just found this old post by Erel with a sample project to send email using gmail


i tried to get the api key but i keep getting errors when the sub send starts on
oauth2.GetAccessToken

the error is from google and the auth screen says client not found

i did create an api key in google console

maybe i'm missing something...

i just took the sample and replace clientid with my api key

any one can help?
 

DonManfred

Expert
Licensed User
Longtime User
See this Tutorial
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
thanks,
got one tiny step ahead
I strongly suggest to use the forumsearch FIRST. And then ask if you do not find a solution.
Seems that you do not use it at all. It is annoying that we always need to do it for you.
i do - all the time - that's how i got this old post
i had a few misunderstandings with what to do
now i got one tiny step ahead as the key is there
now i get another error as the access is not legal
do i have to upload the app to play store first?
it's a testing and learning app so not needed for me to upload
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
one of the issues i have is that the post and explanations are meant for those who are familiar with the api i think
there are options for scopes, test users etc but the explanation in the post doesn't go beyond a photo of the screen after it is all done
this is why i'm lost
is there any one that can explain all required steps so i can make this simple sample work?
it is all about creating the client id and around it iin the console
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
This will let you send via GMail's SMTP system.

The "your-app-specific-password" needs to be created. Go into your Gmail account, Security, search for App Passwords and create one (you just give it a name, google will generate a password for you)


B4X:
Sub Process_Globals
    Dim SMTP As SMTP
End Sub

Sub Globals
    Dim btnSendEmail As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout") ' Assuming you have a button called btnSendEmail in your layout

    ' Initialize the SMTP object
    SMTP.Initialize("smtp.gmail.com", 587, "your-email@gmail.com", "your-app-specific-password", "SMTP")
    SMTP.StartTLSMode = True ' Enable TLS encryption
    SMTP.UseSSL = True ' Enable SSL encryption
    SMTP.AuthMethod = SMTP.AUTH_LOGIN

End Sub

Sub btnSendEmail_Click
    ' Set the details of the email
    SMTP.To.Add("recipient@example.com") ' Recipient's email address
    SMTP.Subject = "Test Email from B4A"
    SMTP.Body = "This is a test email sent from B4A using Gmail's SMTP server."
    SMTP.MailFrom = "your-email@gmail.com"
    SMTP.AddAttachment(File.DirRootExternal, "testfile.txt") ' Add an attachment (optional)
 
    ' Send the email
    SMTP.Send
End Sub

Sub SMTP_MessageSent(Success As Boolean)
    If Success Then
        ToastMessageShow("Email sent successfully!", False)
    Else
        ToastMessageShow("Error sending email: " & LastException.Message, True)
    End If
End Sub
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
ok
here's what i did
  1. in google console i created the oauth2 clientid - goti it
  2. in scopes i marked all gmail options
  3. had to enter test users - added myself
  4. changed in Erel's sample the client id only to mine
  5. did not upload the app to play store - i want to run it in debug locally to test it first
  6. running the app and i get error 400 access denied - invalid request - custom uri scheme is not enabled for your android client
    flowname=generalOAuthFlow
and i'm lost again - what am i missing??
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…