From 0d943843f8d4fb6e1624d5a0a857b3f144b1d6f6 Mon Sep 17 00:00:00 2001 From: Nicolas Sanguinetti Date: Sat, 6 Jun 2015 11:07:19 +0100 Subject: [PATCH] Allow configuring the email envelope on deliver --- lib/malone.rb | 1 + test/malone.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/malone.rb b/lib/malone.rb index 1489fc1..c68cefa 100644 --- a/lib/malone.rb +++ b/lib/malone.rb @@ -30,6 +30,7 @@ def initialize(config) def deliver(dict) mail = envelope(dict) + yield mail if block_given? smtp = Net::SMTP.new(config.host, config.port) smtp.enable_starttls_auto if config.tls diff --git a/test/malone.rb b/test/malone.rb index f6df812..39bfbaf 100644 --- a/test/malone.rb +++ b/test/malone.rb @@ -186,6 +186,15 @@ def SMTP.new(host, port) assert $smtp[:finish] end + test "adding custom headers" do |m| + m.deliver(to: "recipient@me.com", from: "no-reply@mydomain.com", + subject: "Happy new year!", text: "TEXT") do |mail| + mail.add_header("X-MC-SendAt", "2016-01-01 00:00:00") + end + + assert $smtp[:blob].include?("X-MC-SendAt: 2016-01-01 00:00:00") + end + test "calls #finish even when it fails during send_message" do |m| class FakeSMTP def send_message(*args)