I'm using the methods described here Mailto on submit button to generate a new email from inside a form. This is working well, but I'd like to extend it by populating the new email with either the entire contents of the form, or from a saved txt file (~1k) containing the same information. How can I do that? If using the saved version, I'd prefer to see the actual text rather than attaching the file, but either method is ok. I'm pretty new at html, and most of my code borrows heavily from SO, which is a wonderful resource.
Asked
Active
Viewed 44 times
1 Answers
0
IF I understood your question well, you wish to add some content in your email, in format of html or plain text.
You can achieve it using ejs library to render html/text templates in backend/server.
import ejs from 'ejs';
import fs from 'fs';
import path from 'path';
//you need to create your templates first
cosnt htmlTemplate = fs.readFileSync(path.join(__dirname, `/templates/` + fileName + '.html.ejs)).toString();
cosnt textTemplate = fs.readFileSync(path.join(__dirname, `/templates/` + fileName + '.text)).toString();
const html = ejs.render(htmlTemplate);
const text = ejs.render(textTemplate);
// and then use these html/text in your send method
Add template files - mytemplate.text
:
Hi dear client!
Welcome to our community...
or mytemplate.html.ejs
: ... you are going to add the same way as when you write html markup code.

Stefan
- 1,608
- 2
- 14
- 21