iOS Question Open DEFAULT mail client - Mailcomposer does not work anymore

Mike1970

Well-Known Member
Licensed User
Hi everyone, since the new updates of iOS, it is possibile to set a default mail client, different from the "Mail" app from Apple.
I always used the mailcomposer to do this task. But many people (me included) uninstalled "Mail", ans setted another client.

Mailcomposer in this case will not work anymore, will fail the initialization because there is not "Mail" installed....

How can i open always the default mail client?

This is my code:
B4X:
Sub btnRichiedi_Click
    Msgbox2("Msg", "Msg", "Title", Array ("Ok"))
    Wait For Msg_Click (ButtonText As String)
    If ButtonText = "Ok" Then
        Dim email As String = "email@domain.com"
        Dim subject As String = "Subject"
        Dim body As String = ""
       
        Dim su As StringUtils
        Dim url As String = $"mailto:?to=${email}&subject=${su.EncodeUrl(subject, "utf8")}&body=${su.EncodeUrl(body, "utf8")}"$
        If Main.App.CanOpenURL("mailto:") Then
            Main.App.OpenURL(url)
        Else
            SendMail
        End If
    End If
End Sub

Private Sub SendMail
    'always dim and initialize the MailComposer before you use it
    Dim mailcomp As MailComposer
    If mailcomp.IsInitialized Then
        mailcomp.SetToRecipients(Array("email@domain.com"))
        mailcomp.SetSubject("Subject")
        mailcomp.SetBody("Body", True)
        mailcomp.Show(LockPg)
    Else
        Msgbox("Probabilmente non hai installata l'app 'Mail' e non hai configuarato una casella di posta.", "Errore apertura eMail")
    End If
End Sub
SendMail does not work anymore, the mailcomposer is not initializing

Using "mailto:" method instead ask me to download "Mail" again :/

Thanks in advance
 
Last edited:

Mike1970

Well-Known Member
Licensed User
MailComposer will not work if Mail is not installed. You need to check whether it is initialized or check with mailcomp.CanSendMail before you try to use it.

It is based on the native Mail app.
Okok, I read that documentation. I thought there was a method to open the default app, even without mailcomposer.

In this case, it's possibile to retrive which is the default mail app?
 
Top