Message.getAttachments() - possible bug

12 views
Skip to first unread message

Bryan Buchanan

unread,
Jan 17, 2017, 10:55:49 PM1/17/17
to CodenameOne Discussions
I've used code similar to this to add multiple attachments, which works well

Message m = new Message(sb.toString());
m
.setMimeType(Message.MIME_TEXT);
m.getAttachments().put(filename1, "text/html");
m.getAttachments().put(filename2, "text/html");
Message.sendMessage(recipients, "subject", m);

I've just needed to add only one attachment, using the same code, and on Android (only test) Gmail keeps saying it cannot attach the file:

Message m = new Message(sb.toString());
m
.setMimeType(Message.MIME_TEXT);
m.getAttachments().put(filename1, "text/html");
Message.sendMessage(recipients, "subject", m);

I tried a whole bunch of things, thinking it was the file path, message name or content - nothing worked, until I changed the code to:

Message m = new Message(sb.toString());
m
.setMimeType(Message.MIME_TEXT);
m.setAttachment(filename1);
m
.setAttachmentMimeType("text/html");
Message.sendMessage(recipients, "subject", m);

So it appears if you only have one attachment you shouldn't use Message.getAttachments() - is that correct ?

Shai Almog

unread,
Jan 17, 2017, 11:45:48 PM1/17/17
to CodenameOne Discussions
I don't think that should happen, I think that should work for one file too. The one thing that's flaky about that code in Android is the path to the filename which must reside in the users app home directory otherwise things get "wonky".
Reply all
Reply to author
Forward
0 new messages