Android Question Gmail attachments

Detlef Lorenz

Member
Licensed User
Longtime User
I am using the program code of "Android Tutorial [B4X] Sending emails with Gmail REST API" it works almost perfectly. According to the description you can send several attachments, this does not work unfortunately. Only the most recently added attachment will be sent. What am I doing wrong?

B4X:
Sub Button1_Click
    Dim msg As MailCreator
    msg.Initialize
    msg.HtmlBody = True
    msg.ToList.Add("******@gmx.de")
    msg.Subject = "test"
    msg.Body = $"First line<br/>second line"$
    'add attachment
    Dim fd As MultipartFileData
    fd.ContentType = "image/jpeg"
    fd.Dir = File.DirAssets
    fd.FileName = "android.png"
    msg.Attachments.Add(fd)
    fd.ContentType = "image/jpeg"
    fd.Dir = File.DirRootExternal&"/MtoM"
    fd.FileName = "1.jpg"
    fd.ContentType = "image/jpeg"
    fd.Dir = File.DirRootExternal&"/MtoM"
    fd.FileName = "2.jpg"
    msg.Attachments.Add(fd)
    Send(msg)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Dim fd As MultipartFileData
fd.ContentType =
"image/jpeg"
fd.Dir = File.DirAssets
fd.FileName =
"android.png"
msg.Attachments.Add(fd)
fd.ContentType =
"image/jpeg"
fd.Dir = File.DirRootExternal&"/MtoM"
fd.FileName = "1.jpg"
fd.ContentType = "image/jpeg"
fd.Dir = File.DirRootExternal&"/MtoM"
fd.FileName = "2.jpg"
you should use a MultipartFileData for each file! Do not reuse the same object.
 
Upvote 0

Detlef Lorenz

Member
Licensed User
Longtime User
Thank you for the fast answer. It works. I thought it is a variable, I have to assign this only once. I still have to learn a lot.:(
Thanks again DonManfred
 
Upvote 0
Top