Android Question [SOLVED] Long name of mail attachment

Jerryk

Member
Licensed User
Longtime User
B4X:
Private Sub btnSendEmail_Click
    Wait For (FileHandler1.Load("*/*", "Choose file")) Complete (Result1 As LoadResult)
    If Result1.Success Then
        Private fDir, fName As String
        fName = Result1.FileName
        fDir = Result1.Dir

        SMTP1.To.Add("[email protected]")
        SMTP1.Subject = SSSSS"
        SMTP1.Body = "bbbbb"
        SMTP1.AddAttachment(fDir, fName)
        SMTP1.Send
    End If
    
    Sub SMTP1_MessageSent(Success As Boolean)
    Log(Success)
    If Success Then
        ToastMessageShow("Message sent successfully", True)
    Else
        ToastMessageShow("Error sending message", True)
        Log(LastException.Message)
    End If
End Sub

It sends fine, but in the incoming mail the attachment has a path in the name:

content___com.android.externalstorage.documents_document_primary%3ADownload%2Ftest.txt

MessageSend returns false if fName = Result1.RealName is used.
How to make it just only the filename?
 

Jerryk

Member
Licensed User
Longtime User
What is the output of Log(fName) ? content://com.android.providers.downloads.documents/document/msf%3A1000036947

You might need to copy the attachment to XUI.DefaultFolder, send it and then delete it.
I chose test.txt form Download dir.
When I use
File.Copy(fDir, fName, xui.DefaultFolder, fName)
error launched:
java.io.FileNotFoundException: /data/user/0/b4a.example/files/content:/com.android.providers.downloads.documents/document/msf%3A1000036947: open failed: ENOENT (No such file or directory)
or
File.Copy(fDir, Result1.RealName, xui.DefaultFolder, fName)
java.io.FileNotFoundException: No content provider: test.txt
 
Upvote 0
Top