iOS Question How to send email using Gmail app?

JohnC

Expert
Licensed User
Longtime User
I setup a new iPhone 6s and did NOT setup the built-in email app, but instead installed the Gmail app from the app store and set that up to send/rec email.

Apparently, you can't assign the gmail app as an iPhone's default email app (so if you click "mailto:" links on webpages, it will always try to open the built-in email app, even if it's not setup with any accounts!)

So, I want my app to be able to send an email using the installed Gmail app. I am ok if I can't send the email silently and that my app will instead open a new email in Gmail with pre-filled in:
- Destination email
- Subject
- Body
- File Attachment

So then the user will only have to click "Send" inside Gmail to send the email my app created.

The below demo only works with the built-in email app on an iPhone:

So, I have two questions:

1) Is there some equivalent of an "intent" that my app can use to send an email using the Gmail app if it's installed on the user's iPhone?
2) Is there a way to detect that the user installed the Gmail app so I will know to send an intent instead of using the normal composer method to send an email (that uses the built-in email app)?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Source: https://stackoverflow.com/a/30721291/971547

Try this:
B4X:
#QueriesSchemes: googlegmail

Dim email As String = "[email protected]"
Dim subject As String = "subject"
Dim body As String = "test"
Dim url As String = $"googlegmail:///co?to=${email}&subject=${subject}&body=${body}"$
If App.CanOpenURL(url) Then
     App.OpenURL(url)
Else
    Log("gmail not installed")
End If
Note that you need to url encode the parameters with StringUtils (values above do not need to be escaped).
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Source: https://stackoverflow.com/a/30721291/971547

Try this:
B4X:
#QueriesSchemes: googlegmail

Dim email As String = "[email protected]"
Dim subject As String = "subject"
Dim body As String = "test"
Dim url As String = $"googlegmail:///co?to=${email}&subject=${subject}&body=${body}"$
If App.CanOpenURL(url) Then
     App.OpenURL(url)
Else
    Log("gmail not installed")
End If
Note that you need to url encode the parameters with StringUtils (values above do not need to be escaped).

It works - thank you!

Now I just have to figure out how to add an attachment to the intent (openurl).
 
Upvote 0
Top