-1

OK, I have a Form in my web application used to fill out some shipping details. Certain orders require printing this form, to accomplish this I have a Div on the page with the display style set to none. It contains our company logo, shipping information and a table that is dynamically populated with information from the form once the Print button is selected. I am using the InnerHTML of the Div to print with a JavaScript function to print the form.

My problem is I also need to optionally email this as a file attachment. The only way I can see this working would be to save this Div to a file in my application and then attach it to the email.

I have had no success trying save the HTML in to a file though.

I am not stuck to this approach, I am looking for a direction to go in. My only requirements are that the information is sent as an attachment and is visually appealing - including our logo etc.

Thanks for any help - I didn't include any code, didn't seem relevant.. let me know if you want my print function of anything else from the project.

SoundWaves
  • 125
  • 10
  • "I am not stuck to this approach" - Cool, go for it mate ;-)... but on a serious note, YES... provide as much code as is useful to identify how this can be done. – An0nC0d3r Oct 24 '15 at 11:33

1 Answers1

0

You need to improve the design of your application. First, it should be the server side not the client sending the email or processing the order. So forget about JavaScript here unless you are using node.js on the server side. Your server side serves the HTML for the client to display, ideally it is dynamically generated from bits and pieces or using some sort of template. As soon as you have that you can use the same code that generates the HTML served to the client to generate HTML send via email. It may have differences but most building blocks can be reused. Having done that just use whatever email library is available, set the content type to HTML, provide the dynamically generated HTML as the body and off it goes. None of that is done in the client JavaScript.

Oleg Sklyar
  • 9,834
  • 6
  • 39
  • 62
  • OK, I understand. Just to clarify I am just using the JavaScript to print. I am populating the form from the server. I am sending email from the server as well, building the body of the email with HTML wouldn't be a problem. It's building an attachment from HTML I haven't done. – SoundWaves Oct 24 '15 at 11:58
  • Why would you need an attachment? Send it as is, as you would send plain text, but give it a correct mime type. See http://stackoverflow.com/questions/5068827/how-do-i-send-html-email-via-java – Oleg Sklyar Oct 24 '15 at 12:01