问题
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 attched 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 atleast a way to export the local db content into a file using javascript? This file then can be manually attached to the email.
回答1:
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.
来源:https://stackoverflow.com/questions/13683183/attach-content-of-html5-websql-databse-to-email-using-javascript