send email with attachment

The place to discuss anything and everything about running your LiveCode on Android

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
terryho
Posts: 78
Joined: Mon Nov 05, 2012 2:53 pm

send email with attachment

Post by terryho » Mon May 21, 2018 3:10 am

Hi,

I had an apps which can send email in my apps with some of attachment create with my apps.

I use gmail apps to send email, which I can see my attachment in the write email screen, But when send out, there is not attachment.

In the past, I had test which can send email with attachment, But recently it can send email but the attachment can not attach.

Does there any change in Android, which need some kind of permission to sent attachment?

Regards

Terry Ho

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4670
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: send email with attachment

Post by jacque » Mon May 21, 2018 5:50 pm

Are you using mobileComposeMail? Is the attachment a file name or the actual data?

If you can post the handler it would be helpful.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Tue May 22, 2018 2:50 pm

same here: suddenly, since a few months, the attachments stopped to be sent (android app, compiled with LC 7 and LC 9 for vv. 2.3, 4.1 and 5: same issue in all combinations).
here's my code:

Code: Select all

command doEmail pFilePath
 	if the environment is "mobile" then
		if mobileCanSendMail () is false then doAlert "NOEMAILSET"
		put pFilePath into tAttachment["file"]
		//put url ("binfile:" & pFilePath) into tAttachment["data"] -->it's the same…
		put "text/plain" into tAttachment["type"]
		put "file_"& convertDate(the seconds) & (char -4 to -1 of pFile ) into tAttachment["name"]
		put doTranslate("CDEMAILTEXT") into tBody
		put doTranslate("CDEMAILSUBT") into tSubject
		mobileComposeMail tSubject, , , , tBody, tAttachment 
   end if
end doEmail
this code worked fine for months, then a customer alerted me about this issue. i can't say when it begun to fail.

when the email client pops up the message is complete, attachment included (whose size is correct, around 200 KB in my test). but the received message has no file attached.
i tried both using "file" or "data" method.
and it is not an issue related to the receiver: if i check my sent messages folder the message has no attachment.

something happens after having hit the "send" button in the client (gmail app, in my case)

note: if, while choosing the email client to handle the sending, i choose "dropBox" -instead of an email app- the file is saved correctly into the repository.

note2: i tested the same app on iOS 11 and all is working as expected.

bogs
Posts: 2299
Joined: Sat Feb 25, 2017 10:45 pm

Re: send email with attachment

Post by bogs » Tue May 22, 2018 2:58 pm

That sounds more like the attachment is being stripped out by the email host (gmail, in the example you listed).
Image

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Tue May 22, 2018 3:03 pm

bogs wrote:
Tue May 22, 2018 2:58 pm
That sounds more like the attachment is being stripped out by the email host (gmail, in the example you listed).
i thought about that. but, as stated above, i tested the same app on iOS 11 and all is working as expected. same gmail account.

regards

shaosean
Posts: 907
Joined: Thu Nov 04, 2010 7:53 am

Re: send email with attachment

Post by shaosean » Tue May 22, 2018 3:07 pm

If the emails you are sending are not confidential, email them to me <shaosean AT hotmail DOT com>, and I'll take peek..

If this is something you can do quickly, can you modify your program to send the completed email as a plain text email to me?

bogs
Posts: 2299
Joined: Sat Feb 25, 2017 10:45 pm

Re: send email with attachment

Post by bogs » Tue May 22, 2018 3:23 pm

rmuzzini wrote:
Tue May 22, 2018 3:03 pm
bogs wrote:
Tue May 22, 2018 2:58 pm
That sounds more like the attachment is being stripped out by the email host (gmail, in the example you listed).
i thought about that. but, as stated above, i tested the same app on iOS 11 and all is working as expected. same gmail account.
regards
Well, there is a very simple test you can do to determine if it is the program or client/host, compose the mail manually instead of in the program, complete with attachment that is getting sent on the platform giving you the issue (android, gmail app). If you get the same result, i.e. stripped out attachment, then the platform is where your problem is.

The only reason I suspect platform is because of your statement about switching out to dropbox to send raises no issue, which would indicate that the program is working as expected.
Image

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Tue May 22, 2018 3:38 pm

here's attached a simple LC file. in my environment, app built for iOS 9.3 works as expected. app built for android 2.3 (android sdk 25.0.3) fails to send the attachment.
if someone has time to test we'll know more.:-)

regards.
Attachments
test_email.livecode.zip
(2.02 KiB) Downloaded 23 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4670
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: send email with attachment

Post by jacque » Tue May 22, 2018 7:08 pm

Is the file type really plain text? When you tried loading the data itself you used binfile. I've had trouble in the past when declaring the wrong file type.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Wed May 23, 2018 9:22 am

jacque wrote:
Tue May 22, 2018 7:08 pm
Is the file type really plain text? When you tried loading the data itself you used binfile. I've had trouble in the past when declaring the wrong file type.
jacque:
my script used to work fine until a few month ago.
the type of file/data sent is right (don't look at "binfile", it comes from another part of my app where the attachment type is "application/sql")
the same script works like a charm on iOS and the attachments received (in my case: a .txt file in 1 case, a .sql file in another) are perfect.

if you download the attached livecode file you'll see i directly used the example you can read in the manual under "mobileComposeMail"

Code: Select all

 put "Goodbye World!" into tAttachment["data"]
 put "text/plain" into tAttachment["type"]
if you can test this example and all works fine, then the problem is my environment. if it fails, there's a 90% of chance this be a bug. even if i really don't know at which level.
regards.

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Wed May 23, 2018 2:58 pm

update:
i turned on again a very old tablet, running android 4.2.1
on this one, no issue.

whilst no way to send the attachment using a newer tablet running android 7.1.1

therefore, something related to the os version. and, of course, for that reason this issue appeared suddenly,whithout any app update.

now, dear all, the question is:
is this a LC bug?

post here your opinion, please… :-)

bogs
Posts: 2299
Joined: Sat Feb 25, 2017 10:45 pm

Re: send email with attachment

Post by bogs » Wed May 23, 2018 3:25 pm

rmuzzini wrote: now, dear all, the question is:
is this a LC bug?
post here your opinion
My opinion would depend on whether you were able to -
compose the mail manually instead of in the program, complete with attachment that is getting sent on the platform giving you the issue (android, gmail app).
by that I mean composing the mail exactly as your program does, with the same attachment type(binary, data, whatever), on the platform you are having the issue on, not on a previous version, or a completely different OS.

If you are not able to do it manually, it is a platform issue, not a bug. If you *are* able to do it manually, it is more likely a bug, or feature :wink:
Image

terryho
Posts: 78
Joined: Mon Nov 05, 2012 2:53 pm

Re: send email with attachment

Post by terryho » Thu May 24, 2018 4:20 am

Hi all,

I think it may be apps file share permission, I find the following information,

https://developer.android.com/training/ ... e-sharing/

Now I try to add in the example apps.

Regards

Terry Ho

terryho
Posts: 78
Joined: Mon Nov 05, 2012 2:53 pm

Re: send email with attachment

Post by terryho » Thu May 24, 2018 5:10 am

Hi All,

I can confirm that it is gmail email client problem/restriction. Which can use "my.com" apps email client to sent the above example email with attachment.

It seems gmail email client cannot get the attachment in the apps folder.

Regards

Terry Ho

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 58
Joined: Mon Oct 08, 2012 11:30 am

Re: send email with attachment

Post by rmuzzini » Fri May 25, 2018 11:11 am

terryho wrote:
Thu May 24, 2018 5:10 am
Hi All,

I can confirm that it is gmail email client problem/restriction. Which can use "my.com" apps email client to sent the above example email with attachment.

It seems gmail email client cannot get the attachment in the apps folder.

Regards

Terry Ho
GREAT!
thank you for your test, terry.
you reminded me of an issue i got years ago in another android app (it failed to launch a pdf file resident into the app folder and the workaround was to copy first the file into the "documents" folder after having properly set the umask and then to launch that temp copy).

so, it's a matter of permission, in some way. i tried this:

Code: Select all

command doEmail pFilePath
   set the umask to 002
   put ("file_" & (the seconds) & ".txt") into tFileName
   put specialFolderPath("documents") & "/" & tFileName into pFilePath
   put "Goodbye World!" into URL ("file:"&pFilePath)
   answer "Sending the file…" & cr & pFilePath & cr & (there is a file pFilePath) -->"TRUE
   if the environment is "mobile" then
      put pFilePath into tAttachment["file"]
      put "text/plain" into tAttachment["type"]
      put tFileName into tAttachment["name"]
      put "Here's the file!" into tBody
      put "Sending a file" into tSubject
      mobileComposeMail tSubject, , , , tBody, tAttachment  --> ATTACHMENT LISTED IN MESSAGE OPENED BY EMAIL SENDER CLIENT, BUT NOT RECEIVED
   end if
   answer "Opening the file…"
   launch url ("file://" & pFilePath) -->SUCCESS
end doEmail
then i tried this

Code: Select all

command doEmail pFilePath
   set the umask to 002
   put ("file_" & (the seconds) & ".txt") into tFileName
   put specialFolderPath("external documents") & "/" & tFileName into pFilePath -->  --> EXTERNAL STORAGE!
   put "Goodbye World!" into URL ("file:"&pFilePath)
   answer "Sending the file…" & cr & pFilePath & cr & (there is a file pFilePath) -->"TRUE
   if the environment is "mobile" then
      put pFilePath into tAttachment["file"]
      put "text/plain" into tAttachment["type"]
      put tFileName into tAttachment["name"]
      put "Here's the file!" into tBody
      put "Sending a file" into tSubject
      mobileComposeMail tSubject, , , , tBody, tAttachment  --> SUCCESS!!!
   end if
   answer "Opening the file…"
   launch url ("file://" & pFilePath) -->SUCCESS
end doEmail
therefore it's (as often) a LC half bug.
maybe the dictionary should specify that sort of things, saving up hours of testing to developers.
"if you wish to send an attachment under android then don't forget to first copy/create it into the 'external documents' folder (->see) to allow some specific email clients to access it"

thank you a lot again for your hint, terry!
regards

Post Reply

Return to “Android Deployment”