From 457afb90c1d18ef006b8089a76f69656fb8a6638 Mon Sep 17 00:00:00 2001 From: Will Power Date: Tue, 25 Jul 2017 15:47:18 +0100 Subject: [PATCH] don't create empty parts in a multi part email (#267) --- app/models/outgoing_message_prototype.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/outgoing_message_prototype.rb b/app/models/outgoing_message_prototype.rb index 231bbf3..83e04cc 100644 --- a/app/models/outgoing_message_prototype.rb +++ b/app/models/outgoing_message_prototype.rb @@ -163,11 +163,15 @@ class OutgoingMessagePrototype if @html_body.blank? && attachments.empty? mail.body = @plain_body else - mail.text_part = Mail::Part.new - mail.text_part.body = @plain_body - mail.html_part = Mail::Part.new - mail.html_part.content_type = "text/html; charset=UTF-8" - mail.html_part.body = @html_body + if !@plain_body.blank? + mail.text_part = Mail::Part.new + mail.text_part.body = @plain_body + end + if !@html_body.blank? + mail.html_part = Mail::Part.new + mail.html_part.content_type = "text/html; charset=UTF-8" + mail.html_part.body = @html_body + end end attachments.each do |attachment| mail.attachments[attachment[:name]] = {