Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach blob file into HTML href="mailto:"

I have a file available through an URL (need authorization). I created a mailto: link and would like to attach this file in the mail. How can I do that ?

Something like "mailto:[email protected]&attachment=site.com/file.pdf"

like image 890
Charly berthet Avatar asked Jan 02 '23 12:01

Charly berthet


2 Answers

mailto: doesn't support attachments, but there are various ways you could achieve a similar effect:

  1. Link to the file in a message body

    You mentioned that the link needs authorisation, you could generate temporary urls that last 30 minutes (or more/less) which allow for downloads (users can then attach the file themselves)

  2. Send the email yourself

    Your service could send an email to your user (or on behalf of your user) with the attachment using something like Amazon SES, or Mailchimp, etc...

  3. Render your PDF into HTML

    It seems you are planning on attaching PDF files. Depending on the complexity of the PDF files, you could attempt to convert the PDF into email-friendly HTML using one of many tools, such as pdf2htmlEX or Pandoc.

like image 180
Joseph Reeve Avatar answered Jan 05 '23 15:01

Joseph Reeve


If you're hoping for an universal solution, you can't. The mailto protocol described in the RFC 2368 tells us :

The creator of a mailto URL cannot expect the resolver of a URL to understand more than the "subject" and "body" headers.

Even though other headers might be used and understood by some mail clients, this isn't an universally compatible solution. Unless you tell your clients to open these links specifically with a specific mail client that you know supports more headers (like a hypothetical attachment header), you should consider this to not be doable.

like image 30
Kewin Dousse Avatar answered Jan 05 '23 15:01

Kewin Dousse