diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 9bd37fe6d89421215d7002466b45169ac018cbbc..75a855632352066ce75452912ea20cc3e6e419e0 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -165,18 +165,21 @@ class Discussion
 
   # Returns an array of at most 16 highlighted lines above a diff note
   def truncated_diff_lines(highlight: true)
-    initial_lines = highlight ? highlighted_diff_lines : diff_lines
+    lines = highlight ? highlighted_diff_lines : diff_lines
     prev_lines = []
 
-    initial_lines.each do |line|
+    lines.each do |line|
       if line.meta?
         prev_lines.clear
       else
         prev_lines << line
+
         break if for_line?(line)
+
         prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES
       end
     end
+
     prev_lines
   end
 
diff --git a/app/views/notify/_note_mr_or_commit_email.text.erb b/app/views/notify/_note_mr_or_commit_email.text.erb
index 3dd1b4d4c0e642f866e4700a6b9acaced5b1247f..b4fcdf6b1e932db52d86a502959fea0fff5d33a3 100644
--- a/app/views/notify/_note_mr_or_commit_email.text.erb
+++ b/app/views/notify/_note_mr_or_commit_email.text.erb
@@ -1,4 +1,4 @@
-<% if @note.diff_note? && @note.diff_file -%>
+<% if @discussion && @discussion.diff_file -%>
  on <%= @note.diff_file.file_path -%>
 <% end -%>:
 
diff --git a/app/views/notify/_simple_diff.text.erb b/app/views/notify/_simple_diff.text.erb
index 58b0018c0ca864ab293922ccae5322f07d0dc3fe..c28d1cc34d3e394b7f86039f71fd3da885a4911e 100644
--- a/app/views/notify/_simple_diff.text.erb
+++ b/app/views/notify/_simple_diff.text.erb
@@ -1,3 +1,3 @@
 <% @discussion.truncated_diff_lines(highlight: false).each do |line| %>
-  <%= "> " + line.text %>
+> <%= line.text %>
 <% end %>
diff --git a/app/views/notify/note_commit_email.text.erb b/app/views/notify/note_commit_email.text.erb
index dc764b61659e35edbe2071450ad8d69608badb92..6aa085a172e4e0479f802f0046d1e1ce8d7397c1 100644
--- a/app/views/notify/note_commit_email.text.erb
+++ b/app/views/notify/note_commit_email.text.erb
@@ -1,4 +1,2 @@
-<% url = url_for(namespace_project_commit_url(@note.project.namespace, @note.project, id: @commit.id, anchor: "note_#{@note.id}")) %>
-
 New comment for Commit <%= @commit.short_id -%>
-<%= render partial: 'note_mr_or_commit_email', locals: { url: url } %>
+<%= render partial: 'note_mr_or_commit_email', locals: { url: @target_url } %>
diff --git a/app/views/notify/note_merge_request_email.text.erb b/app/views/notify/note_merge_request_email.text.erb
index e33d15daded540bed7ee27556a6f3507a6fc4fe5..2ce64c494cf608ce4b93e7d82d9594433d64b80b 100644
--- a/app/views/notify/note_merge_request_email.text.erb
+++ b/app/views/notify/note_merge_request_email.text.erb
@@ -1,4 +1,2 @@
-<% url = url_for(namespace_project_merge_request_url(@merge_request.target_project.namespace, @merge_request.target_project, @merge_request, anchor: "note_#{@note.id}")) %>
-
 New comment for Merge Request <%= @merge_request.to_reference -%>
-<%= render partial: 'note_mr_or_commit_email', locals: { url: url }%>
+<%= render partial: 'note_mr_or_commit_email', locals: { url: @target_url }%>
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 76ea5f6be31d451d48e7075c89448bc8ff9624c2..1c4ecf83141219ab8ec23a13a5627888aa11dc91 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -50,7 +50,7 @@ describe Notify do
 
           context 'when enabled email_author_in_body' do
             before do
-              allow_any_instance_of(ApplicationSetting).to receive(:email_author_in_body).and_return(true)
+              stub_application_setting(email_author_in_body: true)
             end
 
             it 'contains a link to note author' do
@@ -229,7 +229,7 @@ describe Notify do
 
           context 'when enabled email_author_in_body' do
             before do
-              allow_any_instance_of(ApplicationSetting).to receive(:email_author_in_body).and_return(true)
+              stub_application_setting(email_author_in_body: true)
             end
 
             it 'contains a link to note author' do
@@ -607,7 +607,7 @@ describe Notify do
 
         context 'when enabled email_author_in_body' do
           before do
-            allow_any_instance_of(ApplicationSetting).to receive(:email_author_in_body).and_return(true)
+            stub_application_setting(email_author_in_body: true)
           end
 
           it 'contains a link to note author' do
@@ -726,7 +726,7 @@ describe Notify do
 
         context 'when enabled email_author_in_body' do
           before do
-            allow_any_instance_of(ApplicationSetting).to receive(:email_author_in_body).and_return(true)
+            stub_application_setting(email_author_in_body: true)
           end
 
           it 'contains a link to note author' do