diff --git a/application/Espo/Resources/i18n/en_US/Email.json b/application/Espo/Resources/i18n/en_US/Email.json
index 9243bbb7b2..27d74da782 100644
--- a/application/Espo/Resources/i18n/en_US/Email.json
+++ b/application/Espo/Resources/i18n/en_US/Email.json
@@ -102,7 +102,8 @@
"noSmtpSetup": "No SMTP setup. {link}.",
"testEmailSent": "Test email has been sent",
"emailSent": "Email has been sent",
- "savedAsDraft": "Saved as draft"
+ "savedAsDraft": "Saved as draft",
+ "confirmInsertTemplate": "The email body will be lost. Are you sure you want to insert the template?"
},
"presetFilters": {
"sent": "Sent",
diff --git a/client/src/views/email/record/compose.js b/client/src/views/email/record/compose.js
index 90e25ceae8..31349dacb7 100644
--- a/client/src/views/email/record/compose.js
+++ b/client/src/views/email/record/compose.js
@@ -54,30 +54,27 @@ Espo.define('views/email/record/compose', ['views/record/edit', 'views/email/rec
}
this.listenTo(this.model, 'insert-template', function (data) {
- var body = data.body;
- if (this.hasSignature()) {
- body = this.appendSignature(body || '', data.isHtml);
- }
- this.model.set('isHtml', data.isHtml);
- this.model.set('name', data.subject);
- this.model.set('body', '');
- this.model.set('body', body);
+ var body = this.model.get('body');
- if (this.options.keepAttachmentsOnSelectTemplate) {
- this.initialAttachmentsIds.forEach(function (id) {
- if (data.attachmentsIds) {
- data.attachmentsIds.push(id);
- }
- if (data.attachmentsNames) {
- data.attachmentsNames[id] = this.initialAttachmentsNames[id] || id;
- }
+ var bodyPlain = body.replace(/
/mg, '');
+ bodyPlain = bodyPlain.replace(/<\/p\s*\/?>/mg, '');
+ bodyPlain = bodyPlain.replace(/ /g, '');
+ bodyPlain = bodyPlain.replace(/\n/g, '');
+
+ var $div = $('