[BUG] "IOException while sending message" when trying to send email with attach.

546 views
Skip to first unread message

Hack Tac

unread,
Apr 8, 2016, 9:41:35 AM4/8/16
to DroidScript
Hi! I just found a new bug! I just copied 'Email Send' sample and built an APK file. It can send email to me with attach only if i open app from the Droidscript. But if i open it from already built APK, i will get this notification:

"Failed to send email: IOException while sending message"
I get this alert only if i try to send email with attach from APK. Please fix this bug!

Here is a video about the bug: https://youtu.be/O9kppUN-GCM

jgb

unread,
Jul 19, 2016, 5:20:32 AM7/19/16
to DroidScript
i have the same problem on the built Mail Send.
When i removed the attach by replacing it with Null in the email.Send function, the message was sent  successfully. Seems that something is not right  in getting the path file...

     var attach = "/sdcard/DroidScript/Hello World/Img/Hello World.png";

I tried using...

     var attach = "/storage/emulated/0/DroidScript/Hello World/Img/Hello World.png"

but still got "Failed to send email: IOException while sending message"

 

  

Netpower8

unread,
Jul 19, 2016, 5:26:37 AM7/19/16
to DroidScript
Try it again on the apk app using path that dont start with \

Example. Path is \sdcard\mydir\myfile.txt

Use this instead sdcard\mydir\myfile.txt

Message has been deleted

Steve Garman

unread,
Jul 19, 2016, 5:51:34 AM7/19/16
to DroidScript
Sorry, it's a permissions issue.

The code should work as originally tested if you add this code at the top.

_AddPermissions("Storage");

Steve Garman

unread,
Jul 19, 2016, 6:00:38 AM7/19/16
to DroidScript
For information, this is fixed in the latest alpha, so you should not need the workaround when the next release comes out.

jgb

unread,
Jul 19, 2016, 9:07:48 AM7/19/16
to DroidScript
It works! I applied your solution to  the built  HTTP Server, i can now view the index.html file in my pc's browser. Thank you Steve! Looking forward to the next release.

Steve Garman

unread,
Jul 19, 2016, 9:38:17 AM7/19/16
to DroidScript
Don't get too excited jgb.

As it stands, it will still only work on a device that had DroidScript installed.

jgb

unread,
Jul 23, 2016, 10:52:15 AM7/23/16
to DroidScript
Ok, at least its working in my phone for now. Hope in the future the built apps from DroidScript can work even w/o DroidScript installed.

Steve Garman

unread,
Jul 23, 2016, 11:24:57 AM7/23/16
to DroidScript
It only needs a small alteration to work on a device that does not have DroidScript installed.

You just need to include an html file in your project and change the path the server is pointing to.

It is only the fact that it is an unmodified sample that cause the problem

jgb

unread,
Jul 23, 2016, 11:40:44 AM7/23/16
to DroidScript
Ok, thanks again for additional info. Very nice samples by the way.

Mikhael

unread,
Aug 4, 2020, 5:10:26 AM8/4/20
to DroidScript
I get the same message when I try to send an email with multiple attachments. In DS, the email is sent, but when I compile to the APK, I get the error " Failed to send email: IOException while sending message".

_AddPermissions("Storage"); //The permissions is set in first line

let attach = app.ListFolder(folder).join("|"); // /sdcard/folder/file1.png|/sdcard/folder/file2.png|/sdcard/folder/file3.png
sendEmail(title,msg,to_email,attach);

Mikhael

unread,
Aug 4, 2020, 5:14:49 AM8/4/20
to DroidScript
function sendEmail(subj,body,to_email,attach)
{
    email = app.CreateEmail("te...@mail.ru", "pass");
    email.SetSMTP("smtp.mail.ru", 465);
    email.SetOnStatus((status)=>{
        alert(status);
        });
    email.Send(subj, body, "te...@mail.ru", to_email, attach);
}

Steve Garman

unread,
Aug 4, 2020, 5:23:43 AM8/4/20
to DroidScript
Is your code in the top level directory?

If not your permission line may need to be

_AddPermissions("Network,Storage");

Dave

unread,
Aug 4, 2020, 5:26:29 AM8/4/20
to DroidScript
Maybe try adding the "Network" permission too

_AddPermissions("Storage,Network");

Mikhael

unread,
Aug 4, 2020, 6:25:52 AM8/4/20
to DroidScript
I have Network permission

In my app, I have this: _AddPermissions ("Network, Storage");

Mikhael

unread,
Aug 4, 2020, 3:19:17 PM8/4/20
to DroidScript
If I add only one file to the attach, everything is sent well. But if there are several, the email doesn't leave

Mikhael

unread,
Aug 5, 2020, 4:29:04 AM8/5/20
to DroidScript
what might be the problem?

Mark Allemang

unread,
Nov 20, 2024, 7:32:46 AM11/20/24
to DroidScript
this is only a problem with later versions of android.

On Wednesday, August 5, 2020 at 4:29:04 AM UTC-4 Mikhael wrote:
what might be the problem?

Mark Allemang

unread,
Nov 20, 2024, 10:17:45 AM11/20/24
to DroidScript
so in order to send email with an attachment...i've seen reference to first upload to google drive and then it can be attached to an email...is this a possible solution?
are there any examples?

Dave

unread,
Nov 20, 2024, 1:09:12 PM11/20/24
to DroidScript
For later versions of Android (with scoped storage),  try converting each file path to a full path using app.FullPath() this will only work if you have permission to access the folder containing the attachment files.  If this is not in your scoped area then you will need to ask the user to give permission to the parent folder of the files or use the app.ChooseFile() method instead which will move the chosen file into an accessible area and return the new path.

Dave

unread,
Nov 20, 2024, 1:11:41 PM11/20/24
to DroidScript
app.SendMail might be a simpler solution and you could use the app.ZipFile method to zip up a group of files into a single file.

Mark Allemang

unread,
Dec 27, 2024, 7:22:55 AM12/27/24
to DroidScript
thanks Dave...i'll give the fullpath idea a try....Mark.

Mark Allemang

unread,
Dec 28, 2024, 12:11:43 PM12/28/24
to DroidScript
tried sendmail ...but it requires user interaction.
Couldn't find any info on using app.FullPath().    Any examples or docs?

Mark

Mark Allemang

unread,
Jan 9, 2025, 8:04:31 AMJan 9
to DroidScript
how do I do this?    where can i find reference to app.FullPath   ??

On Wednesday, November 20, 2024 at 1:09:12 PM UTC-5 Dave wrote:

Dave

unread,
Jan 15, 2025, 4:12:40 AMJan 15
to DroidScript
Sorry, I meant to say app.RealPath()

Mark Allemang

unread,
Feb 28, 2025, 11:26:18 AMFeb 28
to DroidScript
thanks Dave.   Ok I got app.RealPath to get my full path to the .jpg file.   But when I pass it as the attachment argument for email.send I still get the ioexception.   So is there some way that I can copy the file into a location where email.send can access it?   without user intervention?   

Dave

unread,
Mar 2, 2025, 10:19:56 AMMar 2
to DroidScript
Where does the file you are trying to send reside exactly?  Is outside your scoped storage?

Mark Allemang

unread,
Apr 1, 2025, 4:14:20 PMApr 1
to DroidScript
yes, I believe it is within scoped storage....it is in the Snaps folder.
/Android/data/com.smartphoneremote.androidscriptfree/files/Snaps

Mark Allemang

unread,
Apr 2, 2025, 2:18:38 PMApr 2
to DroidScript
if there is a better way to do this please let me know.    All I want to do it snap a picture and make it available for viewing elsewhere (without user intervention).....   this could be sending it to google drive or some other cloud storage?....  it doesn't have to be email.    Please,  any suggestions?
Email attachment works fine on droidscript for android older than version 10...i can't easily get a phone that old anymore.

Alan Hendry

unread,
Apr 3, 2025, 3:22:32 PMApr 3
to DroidScript
HI,
There's CreateMail which requires an account and password,
or SendMail (see the docs for notes about OAuth2)
and I as far as i recall the user has to do the send.
I'd try app.getSpecialFolder("Pictures")+"/folder/file.ext"
You may need RealPath.
In a recent post Dave mentioned that for Android 14+
you may need to follow the Storage Access sample
Regards, ah

Jumar

unread,
Apr 3, 2025, 9:54:56 PMApr 3
to DroidScript
Replying to this:


"All I want to do it snap a picture and make it available for viewing elsewhere (without user intervention).....   this could be sending it to google drive or some other cloud storage?....  it doesn't have to be email"

You could try to read the base64 data of the image. You can then send this base64 image data to your server together with other data (fileName, mimeType, or any data you want to save together...)

You could also append the image into a FormData and upload to your server or database such as PocketBase.

Try this one.

This assumes that your snapped photo is located in "Img/my-picture.png"

const formData = new FormData()

const imgPath = "Img/my-picture.png"
const base64Data = app.ReadFileData(imgPath, "base64")
const byteString = atob( base64Data )
const byteArray = Uint8Array.from(byteString, char => char.charCodeAt(0))
const imgFile = new File([byteArray], "my-picture.png", {type: "image/png"})
formData.append("file", imgFile)

** Maybe, some folks here has a cleaner approach.

Regards
Jumar

Jumar

unread,
Apr 4, 2025, 5:06:51 AMApr 4
to DroidScript
Or if you want to send/broadcast email in your DroidScript app. You can use NodeJS and the powerful NodeMailer package. Read more about sending email in DroidScript here

Regards
Jumar

Dave

unread,
Apr 6, 2025, 4:34:06 AMApr 6
to DroidScript
If you are sending a file in scoped storage to another app, such as Gmail, then you might need to convert the path to a URI using the app.Path2Uri() method.  The method will convert any file you have stored in "/Storage/*", /Public/*" or "/Private/*" into a URI which is often required for communicating with external apps since scoped storage was introduced.

Mark Allemang

unread,
Apr 9, 2025, 6:05:29 PMApr 9
to DroidScript
yes CreateEmail is what I'm using:
the example should have the option for attachment removed as it is no longer supported:

Mark Allemang

unread,
Apr 20, 2025, 1:23:29 PMApr 20
to DroidScript
thanks Jumar.   I'm going to base64 encode it, and put it in a  firebase datastore.   Then I'll simply email a link to a webapp to view the encoded uploaded image...that should work perfectly!
thanks again...Mark

Jumar

unread,
Apr 21, 2025, 9:07:45 AMApr 21
to DroidScript
It's easier to use nodemailer package to send emails with attachments like images and other files. If you are creating a Native app, then you can use it via app.CreateNode() component.
Reply all
Reply to author
Forward
0 new messages