1

Using javascript to open email. Email client comes up but no attachment. Can anyone tell me why this isn't working? I have tried multiple ways, /sdcard, /test.png, with "", without "". I have access to External Storage.

window.open('mailto:?subject=' + subject + '&body=This is the body text&attachment="/mnt/sdcard/Test.png"');

Here is my console.log

I/ActivityManager(  152): Displayed android/com.android.internal.app.ResolverActivity: +361ms

I/ActivityManager(  152): Starting: Intent { act=android.intent.action.VIEW dat=mailto:?subject=Test&body=This%20is%20the%20body%20text&attachment=%22/mnt/sdcard/Test.png%22 flg=0x3800000 cmp=com.google.android.email/com.android.email.activity.MessageCompose } from pid 152
user899641
  • 341
  • 1
  • 4
  • 20

1 Answers1

2

You can't specify an attachment using a mailto link. That doesn't work in ANY browser.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • It works on Android. I have an app that I did not create and it works this same way. The email client comes up and the attachment is there. I can't figure out how. – user899641 Aug 24 '11 at 01:14
  • If your code handles the `mailto` link itself and performs the Intent launching with the attachment properly setup, then sure. However, the default URL handler definitely does not support this. – Femi Aug 24 '11 at 01:42
  • Agreed. That's what I can't figure out. How to launch the Intent with the attachment. Any help? – user899641 Aug 24 '11 at 01:47
  • See http://stackoverflow.com/questions/6072895/email-from-internal-storage. You just need to register your own URL handler (if it is in a WebView you can just use a WebViewClient and filter for the `mailto` links). – Femi Aug 24 '11 at 01:53
  • I don't think I'm familiar enough with Java to attempt that without help. I'm building this app with dreamweaver using html and javascript. Any further help or direction would be appreciated. – user899641 Aug 24 '11 at 03:50
  • If you want this to work you will have to become familiar with Java: there is no way to do what you want in JavaScript/HTML. – Femi Aug 24 '11 at 12:56
  • Any chance I could get this to work using: [link](http://smus.com/android-phonegap-plugins) ? – user899641 Aug 24 '11 at 23:36
  • Possibly: hard to tell if it properly handles paths and generates proper URIs and puts them in the right place. In general it is a security hazard to have a browser based email link automatically attach a file: what's to stop a malicious link using the same technique? – Femi Aug 25 '11 at 00:52
  • I definately understand the security issue. However, this will not be a public app so I'm not concerned with that. There has to be a simple way. – user899641 Aug 25 '11 at 01:01