4

I'm using angular to do the following.

How to dynamically generate a text file with some dynamic contents (some what like following)

    dynamic_text() {
        return "dynamic text goes here...";
    }

    download_file(name, contents, mime_type) {
        mime_type = mime_type || "text/plain";

        var blob = new Blob([contents], {type: mime_type});

        var dlink = document.createElement('a');
        dlink.download = name;
        dlink.href = window.URL.createObjectURL(blob);
        dlink.onclick = function(e) {
            // revokeObjectURL needs a delay to work properly
            var that = this;
            setTimeout(function() {
                window.URL.revokeObjectURL(that.href);
            }, 1500);
        };

        dlink.click();
        dlink.remove();
    }

and then attach it to mail

 window.location.href = `mailto:${recepient}?subject=${subject}&body=${body}`;

So that as the user calls the methods it will automatically generate the file with dynamic content and then downloads it & then attaches to the mail/

Though I'm using angular, it is more relate to javascript. So anyone can help!

How to achieve something like this?

zufrieden
  • 40
  • 6
reacg garav
  • 477
  • 1
  • 4
  • 11

1 Answers1

1

According to this answer and RFC 2368, you cannot do this in the front-end, only server-side, for security reasons. Quoting directly:

The user agent interpreting a mailto URL SHOULD choose not to create a message if any of the headers are considered dangerous [...] Only the Subject, Keywords, and Body headers are believed to be both safe and useful.

Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49