Attach content of HTML5 WebSQL database to email using javascript
Asked Answered
M

1

3

I have created local DB (WebSQL) in HTML5. The content of the local storage has to be sent as an attachment in an email. The email client will be opened using javascript mailto feature.

The requirement is when the email client opens it should have the content of the local storage attached as a file (in any file format like xml, csv or text) in the email client window.

As I understand, the content will have to be exported to a file first and then attached to email. Can this be done using File API of HTML5?

My question is - Is it possible to do this using javascript?

EDIT: My problem is that it has to be done entirely on the client side. Is there at least a way to export the local db content into a file using javascript? This file then can be manually attached to the email.

Mcmurry answered 3/12, 2012 at 12:23 Comment(2)
Updated the question for more clarity.Mcmurry
Saving file with File API: eligrey.com/demos/FileSaver.js Or using good old data URI: #3286923Electroencephalograph
E
4

I will assume that you are talking about do something like this (after extract the info from the WebSQL):

document.location = "mailto:"+recipient+"?attach="+"attach.zip";

According to RFC 2368 you can't add an attachment to a message with the mailto: URL scheme due security reasons:

The user agent interpreting a mailto URL SHOULD choose not to create a message if any of the headers are considered dangerous; it may also choose to create a message with only a subset of the headers given in the URL. Only the Subject, Keywords, and Body headers are believed to be both safe and useful.

Conclusion:

mailto: only supports header values or text/plain content.

Alternatives:

  • If you are using PHP you can do this using PHPMailer

  • If you are using C# you can use this class

  • For any other server side language I'm 99% sure that there is a way to do this.

Ellamaeellan answered 4/12, 2012 at 5:48 Comment(1)
See my edit. I have to do it purely on the client side. If local db can atleast be exported to a file, user can attach the file manually to the email. Any idea on how to export the local db to a file?Mcmurry

© 2022 - 2024 — McMap. All rights reserved.