Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach content of HTML5 WebSQL database to email using javascript

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.

like image 560
user32262 Avatar asked May 07 '26 00:05

user32262


1 Answers

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.

like image 113
Tom Sarduy Avatar answered May 09 '26 14:05

Tom Sarduy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!