React: Is there a way to set up a button clicking on which would trigger opening default email client with PDF document attached to it?

Basically I would like to achieve the following result: on a web page user clicks on a Share button and it opens up his default email client with a PDF with the contents of the page attached to it.

I was think to use a combination of html2canvas and react-pdf to generate a PDF page and attach it to this email that would be opened directly from the client side. Is it something possible to implement, or would I need to do it through the server side, or is it something just generally not possible?

I found some topics about it that state that it is only possible to add attachment from the client’s machine, not the web (which includes both React client and Node.JS server that I have spinning on AWS EC2 / or something from AWS S3 bucket, I assume), however I feel like I have seen it being implemented on some sites in the past.

Ideally, in future it would be an overlay opening on Share button that would have options to open email / Slack / MS Teams client with that PDF attachment, but for now just focusing on email part.

There are ways to open the user’s default email client from the browser.

However, I’m not sure if you can auto-insert attachments contents into the email itself. This is probably a security measure because if you can auto-attach a PDF into an email, why couldn’t you do it with an evil file, which would then have to be inside of the email client.

An alternate approach that comes to mind is to send the email from your code itself, rather than the user’s email. However this would mean the email comes from your app. (or some service you end up using instead)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.