# Rendering of e-mail template adds unnecessary whitespace

**URL:** <https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399>\
**Category:** Feature\
**Created:** [2017年五月10日 02:21 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399 "2017-05-10T02:21:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vchuravy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vchuravy/32/120525_2.png) [@vchuravy](https://meta.discourse.org/u/vchuravy)\
**Post date:** [2017年五月10日 02:21 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/1 "2017-05-10T02:21:40Z")

</div>

I have the following e-mail template:

```plaintext
%{message}

%{context}

%{respond_instructions}

```

Which in turn creates the following e-mail

```plaintext
----==_mimepart_59121ceab749e_713fcbab014f1c98278
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<p><div style='margin-left: 15px'><br>[text]</p>

<p>[text]</p>

<p></div></p>

<hr>

<p><a href="[link]">Visit Topic</a> or reply to this email to respond.</p>

<p>You are receiving this because you enabled mailing list mode.</p>

<p>To unsubscribe from these emails, <a href="[LINK]">click here</a>.</p>
----==_mimepart_59121ceab749e_713fcbab014f1c98278--

```

The `<div style='margin-left: 15px'>` creates an unnecessary whitespace indentation and seems odd in itself.

CC: @yuyichao

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2017年五月10日 04:54 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/2 "2017-05-10T04:54:06Z")

</div>

I assume you are objecting to the suppression of avatar in single short email notifications? This was done to satisfy Spam Assassin rules where small emails with images are penalized.

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vchuravy/32/120525_2.png) [@vchuravy](https://meta.discourse.org/u/vchuravy)\
**Post date:** [2017年五月10日 05:17 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/3 "2017-05-10T05:17:15Z")

</div>

No, I disabled the header because a user asked for it and we wanted to make the mailing-list experience more mailinglist like 😉

My issue is that the first paragraph is indented and that makes it look like it might be a citation (which it is not). Looking at the raw html of the e-mail there is a spurious `<div style='margin-left: 15px'>`.

 ![](https://global.discourse-cdn.com/meta/original/3X/7/e/7ece0a6be1c6711ed569530f774bd966cb865381.png)

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2017年五月10日 05:52 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/4 "2017-05-10T05:52:16Z")

</div>

Oh I see @neil can you have a look?

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [2017年五月10日 15:38 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/6 "2017-05-10T15:38:22Z")

</div>

Yeah I see [the problem](https://github.com/discourse/discourse/blob/master/lib/email/styles.rb#L186-L193).

```plaintext
result.gsub!(/\[email-indent\]/, "<div style='margin-left: 15px'>")
result.gsub!(/\[\/email-indent\]/, "</div>")

```

That will create some mangled html.

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [2017年五月10日 18:09 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/7 "2017-05-10T18:09:10Z")

</div>

Fixed.

> <https://github.com/discourse/discourse/commit/5be7a2dad4a3aab55cda43a92a88d39e21011271>

Looks like there was old code trying to indent posts, and it probably worked great… for two days in 2013. [This commit](https://github.com/discourse/discourse/commit/3e7b418ea8d7bb57e5d939ab43c9338170e8f734) became obsolete two days later by [this commit](https://github.com/discourse/discourse/commit/366cb1314063feceff80c0beb8d0ade441e5397f) when a custom html template was used instead of the markdown. Now we allow customized email templates to be used for HTML, which unearthed this archaeological treasure.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2017年五月10日 18:10 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/8 "2017-05-10T18:10:27Z")

</div>

archaeological “treasure”

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [2017年五月26日 19:41 UTC](https://meta.discourse.org/t/rendering-of-e-mail-template-adds-unnecessary-whitespace/62399/9 "2017-05-26T19:41:38Z")

</div>


