iOS Question select image and attach to email

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hi everyone! How can I select an image and attach the file to an email?

my code

B4X:
Sub Botfoto_Click

cam.Initialize("camera",pg)
    cam.SelectFromSavedPhotos(Sender, cam.TYPE_IMAGE)
    
    
End Sub



Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
    Dim p As Phone
    If Success Then
        If Image.IsInitialized Then
            vv.View.Visible = False
            ImageView_imagen.Bitmap = Image
            p.AddImageToAlbum(Image)
            
        Else
            vv.View.Visible = True
            vv.LoadVideo(VideoPath, "")
            Log(p.AddVideoToAlbum(VideoPath, ""))
            
        End If
    End If
End Sub


Sub enviar_mail ()
    
    
    Dim subject As String = evento_electrico & evento_informacion & evento_telefonico & evento_internet &  " " & Editsuministro.Text
    Dim body As String = Editobs.Text
        
    mailc.Initialize("mailc")
    mailc.SetToRecipients(Array("[email protected]"))
    mailc.SetSubject(subject)
    mailc.SetBody(body, True)

    If capturado = True Then
        mailc.AddAttachment(File.DirDocuments,??????) ''<---I don't know the name of the selected image
        
    End If
    
    mailc.Show(pg)
    
End Sub



Sub Mailc_Complete (Result As Int)
    If Result = mailc.RESULT_SENT Then
        Toast.ToastMessageShow("Correo enviado", 3000)
    Else
        Toast.ToastMessageShow("El correo no pudo ser enviado, intente nuevamente", 3000)
    End If
End Sub
 

JohnC

Expert
Licensed User
Longtime User
I don't know how to obtain the image filename when it's added to the album as you are doing with the Phone object, but as a work around you could first save the image in a temp location using a filename of your choice, then specify that filename when sending the email, then delete the image file after the email is sent.
 
Last edited:
Upvote 0
Top