I have an HTML document that I get with
document.body.innerHTML
How to attach this HTML to an email? I want to send this HTML file as an attachment in java/Spring
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Method 1: with a server
If you want to send it to the same server that hosts the HTML file, it is very easy using an ajax call.
For example if you use JQuery, it can be done with:
If the HTML was loaded from local hard disk in the browser or if you want to send the HTML to a host, you should be looking for cross-domain ajax requests.
Depending on your application, you might want to sanitize the HTML and send it with an Ajax request.
Method 2: Without a server
If you want to make a link on the screen which allows the user to send an email with the body that you specify, you can use an anchor tag with
mailto. Please remember to encode the text:Here is a JSfiddle for you to try.