iOS Question Open default email app

kozbot

Member
Licensed User
Longtime User
Hi guys,

I've tried the

Code: Copy
App.OpenURL("email")
but I guess I'm not using the right terminology.

I want to send an email using the default app, but I want to be able to specify the subject as well.

Ideas?

TIA
 
Last edited:
You can use this code:
Code: Copy
Private Sub SendEmail(ToField As String, Subject As String) As Boolean
   If App.CanOpenURL("mailto:") = False Then
     Return False
   Else
     App.OpenURL($"mailto:?to=${ToField}&subject=${Subject}"$)
     Return True
   End If
End Sub
Add this line:
Code: Copy
#QueriesSchemes: mailto
 
Upvote 0
Thanks for that Erel. Do I put the Queries Schemes in the project attributes? I did try it, but I'm getting an error:

LaunchServices: ERROR: There is no registered handler for URL scheme (null)

Thanks.
 
Upvote 0
I'm still getting the same error. I would upload the whole project but it's massive.
Thing is, (I'm gonna use Android terminology) the activity I'm using it on, is not from the front activity... so does that make a difference?
 
Upvote 0
So, THIS works:
Code: Copy
App.OpenURL("mailto:[email protected]")
and it sends to the correct address, but I'm not sure how to put in the subject line. I've tried:
Code: Copy
App.OpenURL("mailto:[email protected]&Subject:App Enquiry")
And
Code: Copy
App.OpenURL("mailto:[email protected]"+"Subject:App Enquiry")
And
Code: Copy
App.OpenURL("mailto:[email protected], Subject:App Enquiry")

But none of them work... I just need to get the subject line in the email. Thanks...
 
Upvote 0
The problem is that your subject contains spaces, and you don't encoded it.

Add the iStringUtils library to your project and use the following code:

Code: Copy
Sub SendEmail(Email As String,Body As String, Subject As String) As Boolean
  
    Dim SU As StringUtils
    Body = SU.EncodeUrl(Body,"UTF-8")
    Subject = SU.EncodeUrl(Subject,"UTF-8")
  
    Dim Url As String = "mailto:" & Email & "?subject=" & Subject & "&body=" & Body
  
    If App.CanOpenURL("mailto:") = False Then
        Return False
   Else
     App.OpenURL(Url)
         Return True
   End If
End Sub
 
Last edited:
Upvote 0
Use this sub and it will work (add a reference to StringUtils):
Code: Copy
Private Sub SendEmail(ToField As String, Subject As String) As Boolean
   If App.CanOpenURL("mailto:") = False Then
     Return False
   Else
     Dim su As StringUtils
     App.OpenURL($"mailto:?to=${ToField}&subject=${su.EncodeUrl(Subject, "utf8")}"$)
     Return True
   End If
End Sub
 
Upvote 0
Back
Top