Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

html - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...