Skip to content
This repository
Browse code

BCC headers are removed when sending via SMTP

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1387 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 508c26c0bbdbe8dbfd8945225d365f8ad06cb616 1 parent ba254b5
Jamis Buck authored
2  actionmailer/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* BCC headers are removed when sending via SMTP #1402
  4
+
3 5
 * Added 'content_type' accessor, to allow content type to be set on a per-message basis. content_type defaults to "text/plain".
4 6
 
5 7
 * Silently ignore Iconv::IllegalSequence errors when converting text #1341 [lon@speedymac.com]
6  actionmailer/lib/action_mailer/base.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'action_mailer/adv_attr_accessor'
2 2
 require 'action_mailer/part'
  3
+require 'tmail/net'
3 4
 
4 5
 module ActionMailer #:nodoc:
5 6
   # Usage:
@@ -280,9 +281,12 @@ def create_mail
280 281
       end
281 282
 
282 283
       def perform_delivery_smtp(mail)
  284
+        destinations = mail.destinations
  285
+        mail.ready_to_send
  286
+
283 287
         Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain], 
284 288
             server_settings[:user_name], server_settings[:password], server_settings[:authentication]) do |smtp|
285  
-          smtp.sendmail(mail.encoded, mail.from, mail.destinations)
  289
+          smtp.sendmail(mail.encoded, mail.from, destinations)
286 290
         end
287 291
       end
288 292
 
2  actionmailer/lib/action_mailer/vendor/tmail/net.rb
@@ -61,7 +61,7 @@ def delete_no_send_fields
61 61
     end
62 62
 
63 63
     def add_message_id( fqdn = nil )
64  
-      self.message_id = ::TMail::new_msgid(fqdn)
  64
+      self.message_id = ::TMail::new_message_id(fqdn)
65 65
     end
66 66
 
67 67
     def add_date
30  actionmailer/test/mail_service_test.rb
@@ -3,6 +3,26 @@
3 3
 require 'test/unit'
4 4
 require 'action_mailer'
5 5
 
  6
+class MockSMTP
  7
+  def self.deliveries
  8
+    @@deliveries
  9
+  end
  10
+
  11
+  def initialize
  12
+    @@deliveries = []
  13
+  end
  14
+
  15
+  def sendmail(mail, from, to)
  16
+    @@deliveries << [mail, from, to]
  17
+  end
  18
+end
  19
+
  20
+class Net::SMTP
  21
+  def self.start(*args)
  22
+    yield MockSMTP.new
  23
+  end
  24
+end
  25
+
6 26
 class TestMailer < ActionMailer::Base
7 27
 
8 28
   def signed_up(recipient)
@@ -467,5 +487,15 @@ def test_html_mail
467 487
     assert_equal "text/html", mail.content_type
468 488
   end
469 489
 
  490
+  def test_headers_removed_on_smtp_delivery
  491
+    ActionMailer::Base.delivery_method = :smtp
  492
+    TestMailer.deliver_cc_bcc(@recipient)
  493
+    assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
  494
+    assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
  495
+    assert MockSMTP.deliveries[0][2].include?(@recipient)
  496
+    assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
  497
+    assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
  498
+    assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
  499
+  end
470 500
 end
471 501
 

0 notes on commit 508c26c

Please sign in to comment.
Something went wrong with that request. Please try again.